Mark Thomas Miller

WordPress custom body class not appearing

If you’re trying to add a custom class to the <body> tag of your WordPress theme but none of your classes are appearing, remember that you need to call WordPress’ body_class() function alongside your HTML:

<!-- Find the body tag in your theme: -->
<body>

<!-- Change it to this: -->
<body <?php body_class(); ?>>

You can then add custom classes with a function such as

add_filter( 'body_class', 'yourtheme_body_class' );
function yourtheme_body_class( $classes ) {
    $classes[] = 'zeph-is-my-favorite';
    return $classes;
}

The above example adds the brilliantly named zeph-is-my-favorite class to the body of your website. You’re allowed to change this to something more appropriate, such as the class you actually want to apply to your body, but you don’t have to. 😉