WordPress automatically adds ‘home’ class to ‘body’ element for the site’s homepage/front page. Wouldn’t it be handier to have a ‘inner’ body class for all the other pages?
This can be done by adding the following in child theme’s functions.php:
add_filter( 'body_class', 'sk_body_class' ); | |
/** | |
* Add "inner" class to 'body' element for inner pages | |
* i.e., for all pages other than site's homepage/front page. | |
* | |
* @author Sridhar Katakam | |
* @link https://sridharkatakam.com/add-inner-body-class-inner-pages-wordpress/ | |
*/ | |
function sk_body_class( $classes ) { | |
if ( ! is_front_page() ) { | |
$classes[] = 'inner'; | |
} | |
return $classes; | |
} |
If the home page is the blog feed, do we also need to specify ! is_home() in the conditional, or will front_page cover that as well?
is_front_page() will cover that as well.
[…] Sridhar Katakam on How to add ‘inner’ body class to all inner pages in WordPress […]
[…] add an inner class to the body element of all pages except that of the homepage per this […]