Title: Problems setting up sidebars
Last modified: August 20, 2016

---

# Problems setting up sidebars

 *  Resolved [tscok](https://wordpress.org/support/users/tscok/)
 * (@tscok)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/problems-setting-up-sidebars/)
 * Hi everyone, I’m really new to WordPress and trying to add sidebars to my theme
   and so I added a bit of code to the functions.php file.
 *     ```
       function arphabet_widgets_init() {
         register_sidebars(3, array(
           'name' => 'Sidebar %d',
           'id' => 'sidebar-$i',
           'before_widget' => '',
           'after_widget' => '',
           'before_title' => '<h4>',
           'after_title' => '</h4>',
         ));
       }
       add_action( 'widgets_init', 'arphabet_widgets_init' );
       ```
   
 * This code is basically a blend of examples I’ve found on codex.wordpress.org 
   and other resources. The problem I’m facing is that the wp-admin/widgets.php 
   is resetting itself when I’m trying to use the above. So if I add widgets to 
   my sidebars and then update the page, the sidebars appear empty again.
 * I found that removing `'id' => 'sidebar-$i',` from the array solved the problem,
   but it feels like an ID is a good thing to have. At least if it gets printed 
   out like a CSS class or ID.
 * I was hoping someone here could help me find a permanent solution.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/problems-setting-up-sidebars/#post-3341935)
 * I believe that one problem is the use of single quotes around ‘sidebar-$i’,. 
   Try using double quotes instead: “sidebar-$i”,
 * Also, the ‘name’ needs to be coded like this:
 *     ```
       'name'          => sprintf(__('Sidebar %d'), $i ),
       ```
   
 *  Thread Starter [tscok](https://wordpress.org/support/users/tscok/)
 * (@tscok)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/problems-setting-up-sidebars/#post-3341941)
 * I tried the double quotes but I’m not sure it helped 🙁
 * When I wrap the sidebar name in the sprintf() function I still get the correct
   number of sidebars but they all end with 0 (zero). And **the original problem**
   persists: the sidebar content disappears on page (wp-admin/widgets.php) reload.
 * After reading the [Function Reference](https://codex.wordpress.org/Function_Reference/register_sidebars),
   under Parameters it describes “name” as such:
 * `name - Sidebar name. (Note: If copying from default usage above, remove sprintf()
   wrapper function.)`
 * This made me think that maybe I should’ve left out the sprintf() function when
   copying the code to my functions.php file.. or maybe my English isn’t good enough
   🙁
 * Just a side note: I’ve seen many examples of how to add multiple sidebars using
   the singular register_sidebar() function multiple times. However, since there
   is a register_sidebar**s**() function to use for multiple registrations, that
   function should be used. Otherwise I just don’t see the point of having this 
   function.
 *  Thread Starter [tscok](https://wordpress.org/support/users/tscok/)
 * (@tscok)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/problems-setting-up-sidebars/#post-3341943)
 * Another thing worth pointing out is that the ‘$i’ varible used in `'id' => "sidebar-
   $i",` is actually adding ‘-‘ before any number. So if you follow the example 
   code in the [Function Reference](https://codex.wordpress.org/Function_Reference/register_sidebars)
   you’ll end up with an ID that looks like `sidebar--n` where _n_ is the ID numbering.
 * Thus, “sidebar$i” will give you the proper ID, namely `sidebar-n`.
 * IMO this should be pointed out the the Function Reference’s parameter description:
 * `id - Sidebar id. (Note: "-$i" is added automatically to supplied 'id' value 
   after the first; e.g., "Sidebar", "Sidebar-2", "Sidebar-3", etc.)`
 * This is all very confusing. Is there something buggy about the function reference
   or am I just unlucky?
 *  Thread Starter [tscok](https://wordpress.org/support/users/tscok/)
 * (@tscok)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/problems-setting-up-sidebars/#post-3341952)
 * Okay, I found this to be working:
 *     ```
       function arphabet_widgets_init() {
         $args = array(
           'name' => __('Sidebar %d'),
           'id' => "sidebar".$i,
           'before_widget' => '',
           'after_widget' => '',
           'before_title' => '<h4>',
           'after_title' => '</h4>'
         );
         register_sidebars(3, $args);
       }
       add_action( 'widgets_init', 'arphabet_widgets_init' );
       ```
   
 * The main difference is how you apply the ID `'id' => "sidebar".$i,`. I tried 
   different ways but found this way to be the best.
 * I also removed the last comma, after the closing `</h4>`. Only because there 
   are no further key/value pairs in the array.
 * Finally I slapped on the __() function on “name” since it is some kind of alias
   function of translate(). I guess it can’t hurt to have it there although I don’t
   know what good it does.
 * So, that’s it. I hope this thread can be of help to someone else.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Problems setting up sidebars’ is closed to new replies.

## Tags

 * [functions](https://wordpress.org/support/topic-tag/functions/)
 * [register_sidebars](https://wordpress.org/support/topic-tag/register_sidebars/)
 * [widgets](https://wordpress.org/support/topic-tag/widgets/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [tscok](https://wordpress.org/support/users/tscok/)
 * Last activity: [13 years, 4 months ago](https://wordpress.org/support/topic/problems-setting-up-sidebars/#post-3341952)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
