Adding CSS Classes to Widgets
-
I know that I can assign classes and unique IDs to Widgets via the following code:
register_sidebar(array( 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h2>', 'after_title' => '</h2>', ));I also know that I can list all of the available Widgets via this code:
print_r(wp_get_sidebars_widgets());But is there any way to add an additional CSS class to the ‘before_widget’ parameter to denote the Widget’s position? So that I might end up with…
<div id="linkcat-2" class="widget widget-1 widget_links"></div> <div id="rss-2" class="widget widget-2 widget_rss"></div> <div id="linkcat-16" class="widget widget-3 widget_links"></div>As a client might add, remove or re-order Widgets within a sidebar, I want to avoid targeting a Widget via its ID within my CSS. I need to be able to style the first Widget within each sidebar.
Can anyone help or offer any ideas?
The topic ‘Adding CSS Classes to Widgets’ is closed to new replies.