Last active
May 30, 2018 12:41
-
-
Save rxnlabs/4897ee1153534ca17b4860c142ff7886 to your computer and use it in GitHub Desktop.
WordPress - Get the name and id of the widget area being used to display a certain widget. This adds the widget ID and widget area name as HTML comments to the frontend of the site
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
<?php | |
/** | |
* Add the widget ID and widget name as HTML comments. | |
* | |
* Makes it easiser to identify exactly which widget area a widget is appearing in. | |
* This helps a lot with themes that have a lot of sidebars and uses a lot of widgets. | |
*/ | |
function which_dynamic_sidebar( $sidebar_params ) { | |
$sidebar_params['0']['class'] = empty( $sidebar_params['0']['class'] )?$sidebar_params['0']['id']:$sidebar_params['0']['class'].' '.$sidebar_params['0']['id']; | |
$sidebar_params['0']['before_widget'] = '<!--Widget-Area:id:'.esc_attr($sidebar_params['0']['id']).';name:'.esc_attr($sidebar_params['0']['name']).'-->'.$sidebar_params['0']['before_widget']; | |
return $sidebar_params; | |
} | |
add_filter( 'dynamic_sidebar_params', 'which_dynamic_sidebar', 10 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment