Created
June 30, 2014 18:03
-
-
Save iamcanadian1973/82df22e860ef2e7a8dd6 to your computer and use it in GitHub Desktop.
Flexible Posts Widget - add template name as class to widget. Because you can have multiple templates, its nice to be able to style them individually.
This file contains 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_filter( 'widget_display_callback', 'kr_widget_display_callback', 10, 3 ); | |
function kr_widget_display_callback($instance, $widget, $args) { | |
if ( strpos( $args['widget_id'], 'dpe_fp_widget' ) === FALSE && !isset($instance['template'])) { | |
return $instance; | |
} | |
$widget_classname = $widget->widget_options['classname']; | |
$my_classnames = basename( $instance['template'], '.php' ); | |
$args['before_widget'] = str_replace($widget_classname, "{$widget_classname} {$my_classnames}", $args['before_widget']); | |
$widget->widget($args, $instance); | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment