Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I registered a sidebar widget, then modified the registration which included changing the registered name of the widget. Now the widget does not show at all. Below are the steps I took.

  1. I registered a sidebar widget in my functions.php file.

    if (function_exists('register_sidebar') ){
        register_sidebar( array('name' => 'Right Sidebar') );
    }
    
  2. In my template page, I then dropped in the appropriate calls for the widget, like so...

    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
        ...some html...
    <?php endif; ?>
    
  3. Then after doing some further reading in the codex (i'm a noob), I decided to do a bit more clean-up and test out all the parameters of register_sidebar(), so...

  4. In functions.php, I CHANGED the call from the above to this (which is taken directly from the codex):

    if (function_exists('register_sidebar') ){
        register_sidebar(array(
          'name' => 'RightSideBar',
          'id' => 'right-sidebar',
          'description' => 'Widgets in this area will be shown on the right-hand side.',
          'before_title' => '<h1>',
          'after_title' => '</h1>'
        ));
    }
    
  5. I then went to Admin > Appearance and, sure enough the new and improved sidebar widget was showing, but was empty. So I added a few widgets.

  6. I then tested the page in the browser: No Widgets. Just the default mark-up I added.

  7. I checked the code. Looks right to my noob eyes.

  8. So I decided to back out of the changes and reverted to the previous code (see step 1).

  9. To my amazement, in the admin all the previous settings were still there (Sidebar, widgets and all)! Plus the widgets showed right up on the page.

  10. Then I re-added the new code (see #4) and, same thing: All the widgets I added to the new and improved version also were saved (somewhere in the db, for some reason beyond my pay grade) and also showed (in the admin section, but NOT on the page).

  11. This leads to the question: Do I need to (somehow) deregister the sidebar widget? ( since the DB is apparently storing these values "somewhere").

  12. A bit more digging pulled up this little function: unregister_sidebar( $id );

  13. Do I really need to use this? My original goal was to completely rename and update the sidebar.

So... I need a clue :D

Thanks,

sleeper

share|improve this question

1 Answer 1

up vote 2 down vote accepted
  1. If you don't need the others settings from register_sidebar, that's fine.

  2. That's not fine. :) To render your sidebar you need to call

     dynamic_sidebar($index);
    

    In your case it would be:

     dynamic_sidebar('Right Sidebar');
    

    see the codex page for dynamic sidebar http://codex.wordpress.org/Function_Reference/dynamic_sidebar

    Your current code says (short version): If there is no sidebar, then do my custom code. Look at the examples from the linked codex page.

  3. skipped

  4. If you need those settings for a sidebar, use them, but notice, and that's what happend on your sidebar/widget configuration page when your old sidebar disappeared.

If you register a sidebar with an ID, WordPress looks in the database for this ID, if you just register a sidebar with a name, WordPress will look for the name.

Your ID was different from the original name, and there was no entry for a sidebar with this id. The name gets ignored, when an ID is set.

Hope that makes things a bit more clear.

share|improve this answer
    
Thank you for your reply. It was "spot on"! I modified code to use your #2 (also wrapped in an if ( function exists ( 'dynamic_sidebar' ) ) {...) and all is well. Also reviewed the codex link in #2 and I understand everything BUT the example used. Are they saying to declare TWO UL's: one for not dynamic and one for dynamic? –  sleeper Feb 2 '12 at 10:21
    
p.s. Looking at sidebar.php really cleared things up. –  sleeper Feb 2 '12 at 10:28
    
using <ul> is kind of "best practice" since the default settings for 'before_widget' and 'after_widget' are <li> resp. </li>. you can overwrite this when defining your sidebar if you don't want to wrap your widgets inside a <ul>. more a question about semantics actually. –  ungestaltbar Feb 2 '12 at 10:45
    
Got it. I'm sticking with the best practices for now. :D –  sleeper Feb 2 '12 at 11:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.