Support » Fixing WordPress » register_sidebar() not working as I thought it would

  • mrapino



    I am registering a new sidebar, and then placing into my child theme:

      'name' => __( 'Top Text Bar' ),
      'id' => 'top-bar',
      'description' => '',
      'class' => 'top-bar',
      'before_widget' => '<div id="%1$s" class="widget %2$s">',
      'after_widget'  => '</div>',
      'before_title' => '',
      'after_title' => ''

    Where I am using 'before_widget' => '<div id="%1$s" class="widget %2$s">',, I thought my front-end code would look like:

    <div id="top-bar" class="top-bar">

    But instead, it looks like:

    <div id="text-5" class="widget widget_text">

    Can someone tell me what I am doing wrong? I thought that if you defined an ID and Class within your register_sidebar function, it was supposed to use them within your front-end markup?


Viewing 7 replies - 1 through 7 (of 7 total)
  • The ID is used by WordPress internally to identify each sidebar, it doesn’t have to do with the HTML being generated. Class should be appearing in the HTML for use with your CSS. However, it applies to the sidebar as a whole and not the individual widgets.



    Thanks for the reply. As you can see from my markup example, the class isn’t being using in the HTML for use with my CSS. The class I want is “top-bar”, however, what I am getting is “widget widget_text”.

    Any suggestions?

    Can you post the HTML output for the entire sidebar?

    Also, why not just add the top-bar class to the class declaration in ‘before-widget’ instead?



    Yeah, that’s what I am going to do. I was just curious why the class attribute in the function wasn’t actually doing what it was supposed to.


    I did some research and apparently that’s more common than one would think. I’ve never really tried to use it, so I’m not sure why that is. It should work fine adding it to ‘before-widget’ though.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘register_sidebar() not working as I thought it would’ is closed to new replies.