
By default, the body_class() function adds some class to the <body> tag to allow you to style your site more easily. But unfortunely, no extra class is added when your template has a sidebar. Here is a imple function to solve this problem.

By default, the body_class() function adds some class to the <body> tag to allow you to style your site more easily. But unfortunely, no extra class is added when your template has a sidebar. Here is a imple function to solve this problem.
To apply the hack, just paste the code below into your functions.php file.
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');
Thanks to WP Function for the tip!
2 Responses
Awesome thanks for sharing I was looking for a code snippet like this today and discovered this which worked perfectly.
For non-tech people like me, could you supply and example what this hack would look like? Thanks.
Trackbacks: