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.

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

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
add comment

1 Answer

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
add comment

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.