Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('dynamic_sidebar_params', 'add_classes_to__widget');
- function add_classes_to__widget( $params ){
- $all_sidebars = wp_get_sidebars_widgets(); // get an array of all the sidebars
- $footer_sidebar = $all_sidebars['footer_sidebar']; // you need to know which sidebar you're getting: use its ID to select it.
- // this creates an array of the widgets shown in that sidebar, in order.
- // find the position of the widget ID in the array:
- $array_position = array_search ( $params[0]['widget_id'], $footer_sidebar );
- // so for the widget we're working on, its position is now in $array_position where 0 = first widget.
- if ( 2 === $array_position ){ // in this case the THIRD widget is smaller...
- $classe_to_add = 'col-2 '; // make sure you leave a space at the end
- $classe_to_add = 'class="'.$classe_to_add;
- $params[0]['before_widget'] = str_replace( 'class="', $classe_to_add,$params[0]['before_widget'] );
- } elseif ( 3 === $array_position ) { // and the FOURTH widget is larger...
- $classe_to_add = 'col-4 '; // make sure you leave a space at the end
- $classe_to_add = 'class="'.$classe_to_add;
- $params[0]['before_widget'] = str_replace( 'class="', $classe_to_add,$params[0]['before_widget'] );
- } else { // and all other widgets are normal.
- $classe_to_add = 'col-3 '; // make sure you leave a space at the end
- $classe_to_add = 'class="'.$classe_to_add;
- $params[0]['before_widget'] = str_replace( 'class="', $classe_to_add,$params[0]['before_widget'] );
- }
- return $params;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement