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

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'); ">

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');
Leave a comment

0 Comments.

Leave a Reply


[ Ctrl + Enter ]

*

Wordpress Freelancer, Joomla Freelancer Web designer Mumbai india, Wordpress web developer India, Joomla Web developer india, Outsourcing web project india mumbai

By Santosh Kori Published: October 10, 2012 Professional Freelance Website developer 5 stars based on 65 reviews Total time: 24 hour 00 min Wordpress Joomla XHTML CSS jQuery HTML5 eCommerce CSS3 ☞ Offers low cost freelance web designing, asp php asp.net web development services from Mumbai India. Freelance web designer & developer Mumbai India.