Home » Wordpress » Wordpress Tip and Tricks » How to automatically add a class to body_class if there’s a sidebar

To apply the hack, just paste the code below into your functions.php file to add automatically body class to body tag based on sidebar active.

function wpfme_has_sidebar($classes) {
    if (is_active_sidebar('sidebar')) {
        // add 'class-name' to the $classes array
        $classes[] = 'has_sidebar';
    }
    // return the $classes array
    return $classes;
}
add_filter('body_class','wpfme_has_sidebar');

Array ( [0] => Wordpress Tip and Tricks )

Leave a comment

0 Comments.

Leave a Reply

You must be logged in to post a comment.