0

This is my sidebar code

register_sidebar(array(
        '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

register_sidebar(array(
            '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

1
  • 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.
    – Evan Yeung
    Commented Feb 7, 2012 at 8:36

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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