Skip to content

Instantly share code, notes, and snippets.

@bueltge
Created April 21, 2012 21:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bueltge/2439694 to your computer and use it in GitHub Desktop.
Save bueltge/2439694 to your computer and use it in GitHub Desktop.
WordPress Widget Order via CSS; Here is a simple filter to automatically add a class attribute like widget-order-1 to all widgets within sidebars
add_action( 'init', 'add_widget_order_class' );
function add_widget_order_class() {
global $wp_registered_sidebars, $wp_registered_widgets;
$sidebars = wp_get_sidebars_widgets();
if ( empty( $sidebars ) )
return;
foreach ( $sidebars as $sidebar_id => $widgets ) {
if ( empty( $widgets ) )
continue;
foreach ( $widgets as $i => $widget_id ) {
$order = $i + 1;
$wp_registered_widgets[$widget_id]['classname'] .= ' widget-order-' . $order;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment