Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. add_filter('dynamic_sidebar_params', 'add_classes_to__widget');
  2. function add_classes_to__widget( $params ){
  3. $all_sidebars = wp_get_sidebars_widgets(); // get an array of all the sidebars
  4. $footer_sidebar = $all_sidebars['footer_sidebar']; // you need to know which sidebar you're getting: use its ID to select it.
  5. // this creates an array of the widgets shown in that sidebar, in order.
  6.  
  7. // find the position of the widget ID in the array:
  8. $array_position = array_search ( $params[0]['widget_id'], $footer_sidebar );
  9. // so for the widget we're working on, its position is now in $array_position where 0 = first widget.
  10.  
  11. if ( 2 === $array_position ){ // in this case the THIRD widget is smaller...
  12. $classe_to_add = 'col-2 '; // make sure you leave a space at the end
  13. $classe_to_add = 'class="'.$classe_to_add;
  14. $params[0]['before_widget'] = str_replace( 'class="', $classe_to_add,$params[0]['before_widget'] );
  15. } elseif ( 3 === $array_position ) { // and the FOURTH widget is larger...
  16. $classe_to_add = 'col-4 '; // make sure you leave a space at the end
  17. $classe_to_add = 'class="'.$classe_to_add;
  18. $params[0]['before_widget'] = str_replace( 'class="', $classe_to_add,$params[0]['before_widget'] );
  19. } else { // and all other widgets are normal.
  20. $classe_to_add = 'col-3 '; // make sure you leave a space at the end
  21. $classe_to_add = 'class="'.$classe_to_add;
  22. $params[0]['before_widget'] = str_replace( 'class="', $classe_to_add,$params[0]['before_widget'] );
  23. }
  24. return $params;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement