Created
November 29, 2015 01:06
-
-
Save lgedeon/d9b836443379b02f3a07 to your computer and use it in GitHub Desktop.
Target specific widgets by title
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 | |
function helper__dynamic_sidebar_params__title_class ( $instance, $widget, $args ) { | |
if ( isset( $instance['title'] ) ) { | |
$new_class = implode( '_', array( 'widget', $widget->id_base, sanitize_title( $instance['title'] ) ) ) . " "; | |
$args['before_widget'] = str_replace( 'class="', 'class="' . $new_class, $args['before_widget'] ); | |
// For lack of a proper filter, let's just do this ourselves - will have to keep up to date with WP, though. | |
$was_cache_addition_suspended = wp_suspend_cache_addition(); | |
if ( $widget->is_preview() && ! $was_cache_addition_suspended ) { | |
wp_suspend_cache_addition( true ); | |
} | |
$widget->widget( $args, $instance ); | |
if ( $widget->is_preview() ) { | |
wp_suspend_cache_addition( $was_cache_addition_suspended ); | |
} | |
// Return false to prevent display since we just did it | |
return false; | |
} | |
return $instance; | |
} | |
add_filter( 'widget_display_callback', 'helper__dynamic_sidebar_params__title_class', 10 , 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment