SHARE
TWEET

Untitled

a guest Apr 20th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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' );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top