Created
April 21, 2012 21:24
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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