Created
April 10, 2019 17:43
-
-
Save Asikur22/10e6e5b41dfb8e1149c42ff592a483ce to your computer and use it in GitHub Desktop.
[Add Extra CSS Class to Widget]
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 Extra CSS Class to Widget | |
| */ | |
| function add_extra_class_to_widget( $params ) { | |
| // get widget vars | |
| $widget_name = $params[ 0 ][ 'widget_name' ]; | |
| $widget_id = $params[ 0 ][ 'widget_id' ]; | |
| // bail early if this widget is not a Text widget | |
| if ( $widget_name != 'Text' ) { | |
| return $params; | |
| } | |
| // add Class to before_widget | |
| $class = 'my-class'; | |
| // Get class name from ACF Fields | |
| // $class = get_field( 'class', 'widget_' . $widget_id ); | |
| if ( $class ) { | |
| $classe_to_add = 'class="' . $class . ' '; | |
| $params[ 0 ][ 'before_widget' ] = str_replace( 'class="', $classe_to_add, $params[ 0 ][ 'before_widget' ] ); | |
| } | |
| return $params; | |
| } | |
| add_filter( 'dynamic_sidebar_params', 'add_extra_class_to_widget' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment