WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is my sidebar code

        'name' => 'Post Sidebar',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div></div>',
        'before_title' => '<div class="titlediv">',
        'after_title' => '</div><div class="widgetdiv">',

The above code displays widget title and widget content in separate divs. I want them in separate div because i want to implement collapse feature in widget.

Now here is my problem. I don't want that id before widget. I need it after title. I modified the code like this

            'name' => 'Post Sidebar',
            'before_widget' => '<div class="widget %2$s">',
            'after_widget' => '</div></div>',
            'before_title' => '<div class="titlediv">',
            'after_title' => '</div><div id="%1$s"  class="widgetdiv">',

But its not working. Can anyone help me? Thanks

share|improve this question
I don't think the id is passed to the after_title. You may be able to plug into it to change that, but have you tried calling the .widgetdiv through its parent? $(.widget#id .widgetdiv) I used jQuery as an example, you can easily adapt it to your script. – imHavoc Feb 7 '12 at 8:36
up vote 0 down vote accepted

No offense, but your code is a COMPLETE mess, so I'm just going to give you clean code and then tell you how to target it.

register_sidebar( array(
        'name' => 'Post Sidebar',
        'before_widget' => '<div id="%1$s" class="widget widget-%2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<div class="titlediv">',
        'after_title'   => '</div>',
) );

Then to target the title via the id you can use CSS and say something like #id .titlediv. This way, you retain the ability to target the entire widget and you can target the title individually.

A word on the changes I made: I know you were wrapping the widget content in a <div>, but this is not the correct approach. Content wrapping like that should be done in the widget's code, not at the widget definition code, as some widgets will not display correctly with that method.

share|improve this answer

Your Answer


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.