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.

2 Answers
2

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.

Leave a Reply

Your email address will not be published. Required fields are marked *