WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

I try to get the collapsible-widget-area plugin so that every widget it creates inside the collapsible area has a unique id <div> after its title.

function get_args() {
    $this->args = apply_filters( 'collapsible-widget-area-args', array(
        'name'          => __( 'Collapsible Widget Area', 'collapsible-widget-area' ),
        'id'            => 'collapsible-widget-area',
        'description'   => __( 'Drag widgets into this area in order to use them inside of the Collapsible Widget.', 'collapsible-widget-area' ),
        'before_widget' => '<div id="%1$s" class="widget %2$s collapsible-item">',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="widgettitle">',
        'after_title'   => '</h2><div id="i_want_to_be_a_unique_id_for_every_widget_but_i_am_not"></div>',
    ) );
    $this->sidebar_id = $this->args['id'];
    if ( ! class_exists( 'collapsible_widget' ) ) {
        require_once( 'class.collapsible-widget.php' );
    add_action( 'widgets_init', array( $this, 'register_widget' ) );

This is the function that sets the args, but as far as i understand it, it is only called one time and the arguments apply to every widget. Can somebody tell me now to use seomthing like the %1$s for the before_widget or even better the exact same value in the after_title?

The entire plugin can be viewed at in the wordpress plugin svn, the function i am shoing above is in the class.collapsible-widget-area.php and the only thing i added so far is the <div id="i_want_to_be_a_unique_id_for_every_widget_but_i_am_not"></div>.

This is not a "write me a programm" question, its just a example i give. Maybe there needs to be a complete other solution to accomplish this, or its very easy to do with this plugin wich already extends wordpress widget class, i don't know.

share|improve this question
Is there a reason you can't use the ID on before_widget to select the div (e.g. #unique-widget-id .after-widget-title?) – mrwweb May 15 '12 at 2:03
if course there is a reason, i want to use twitter bootsrap collapse (accordion) javascript with it and its needs special markup, i don't want to change it. – amy May 15 '12 at 2:37
up vote 2 down vote accepted

Looking at widget.php in trac sprintf() only runs on before_widget (Line 884):

$params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);

Hence, it won't work for any of the other arguments.

I wondered whether you could use the dynamic_sidebar_params filter, but the $id and $classname_ arguments aren't passed on to the filter. Outside of hacking core, I'm not sure there's much you can do other than look into modifying Twitter bootstrap or using jQuery to add on the ID after the page load.

share|improve this answer
No way to create a function, extending a class to get this done? Anyway i have a jquery solution now, since the accordion uses jquery anyway it does not matter that it relies on ids and links created in jquery now. – amy May 18 '12 at 15:59

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.