Joined June 2012
·

Leonardo Prado

Software Engineer at Kanui
·
Sao Paulo / Brazil
·
·
·

Thanks for pointing this out, @mikeymo! :)

We can also move the widget call outside the IF, to make cleaner

function add_widget_title_to_before_widget( $instance, $widget_class, $args ) {
    if ( ! empty( $instance['title'] ) ) {
        $new_class = 'class="' . sanitize_title( $instance['title'] ) . ' ';
        $args['before_widget'] = str_replace('class="', $new_class, $args['before_widget']);
    }
    $widget_class->widget( $args, $instance );
    return false;
}
Posted to Wordpress widget title as class name over 1 year ago

@dalenberg Yes, there's a way to change the widget class. As it is a little tricky to do, I've created another tip => https://coderwall.com/p/hynjha

Achievements
278 Karma
13,213 Total ProTip Views