I would like to use toggle option in my sidebar widgets. But my sidebar widgets not generating unique id.
This is my register sidebar code.
register_sidebar(array(
'name' => 'Main Sidebar',
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div></div></div>',
'before_title' => '<div class="titlediv">',
'after_title' => '<a class="dropdown" style="float: right;" href="#%1$s" data-toggle="collapse"><b class="toggleicon"></b></a></div><div id="%1$s" class="collapse in"><div id="%1$s" class="boxdiv">'
)
This is how i’m getting output
<div class="widget widget_stc-followers">
<div class="titlediv">Widget Title<a class="dropdown" style="float: right;" href="#%1$s" data-toggle="collapse"><b class="toggleicon"></b></a></div><div id="%1$s" class="collapse in"><div id="%1$s" class="boxdiv">
Widget content
</div></div></div>
I mean %1$s
not working in after_title
. I want to use unique id. So can anyone give me some tips to make it work?
Thanks
The
after_title
does not go through any transformations. In fact only thebefore_widget
does:http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/widgets.php#L876
However, a little lower you can see that
$params = apply_filters( 'dynamic_sidebar_params', $params );
there’s a filter you can hook to do your own filtering.This is the general answer to why your IDs are not getting rendered. From this example, to generate your own unique IDs in the
after_title
key, you would need to do something similar, but provide unique IDs, like so:Note: Id needs to be unique and you are trying to set the same id to 2 different div’s.
Now id
%1$s
and class%2$s
attributes only work in thebefore_widget
argument as far as i know but you can use to toggle you widgets based on but with a bit more then justdata-toggle="collapse"
.