Posted By

lashon on 05/29/12


Tagged

wordpress


Versions (?)

Add the Order of Widgets Within a Sidebar as a CSS Class to All Widgets


 / Published in: PHP
 

URL: http://konstruktors.com/blog/wordpress/3615-add-widget-order-css-class-sidebar/

Here is a simple filter to automatically add a class attribute like widget-order-1 to all widgets within sidebars (from konstruktors.com)

  1. add_action('init', 'add_widget_order_class');
  2. function add_widget_order_class() {
  3. global $wp_registered_sidebars, $wp_registered_widgets;
  4. $sidebars = wp_get_sidebars_widgets();
  5. if (empty($sidebars))
  6. return;
  7. foreach ($sidebars as $sidebar_id => $widgets) {
  8. if (empty($widgets))
  9. continue;
  10. foreach ($widgets as $i => $widget_id) {
  11. $order = $i + 1;
  12. $wp_registered_widgets[$widget_id]['classname'] .= ' widget-order-' . $order;
  13. }
  14. }
  15. }

Report this snippet  

You need to login to post a comment.