Skip to content

Instantly share code, notes, and snippets.

@iamcanadian1973
Created June 30, 2014 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamcanadian1973/82df22e860ef2e7a8dd6 to your computer and use it in GitHub Desktop.
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.
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