Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. /*
  2. * Add Extra CSS Class to Widget
  3. */
  4. function add_extra_class_to_widget( $params ) {
  5.  
  6. // get widget vars
  7. $widget_name = $params[ 0 ][ 'widget_name' ];
  8. $widget_id = $params[ 0 ][ 'widget_id' ];
  9.  
  10. // bail early if this widget is not a Text widget
  11. if ( $widget_name != 'Text' ) {
  12. return $params;
  13. }
  14.  
  15. // add Class to before_widget
  16. $class = 'my-class';
  17.  
  18. // Get class name from ACF Fields
  19. // $class = get_field( 'class', 'widget_' . $widget_id );
  20.  
  21. if ( $class ) {
  22. $classe_to_add = 'class="' . $class . ' ';
  23. $params[ 0 ][ 'before_widget' ] = str_replace( 'class="', $classe_to_add, $params[ 0 ][ 'before_widget' ] );
  24. }
  25.  
  26. return $params;
  27. }
  28. add_filter( 'dynamic_sidebar_params', 'add_extra_class_to_widget' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement