How do I add a custom body class for a specific page ID?

The ID can/should be given without quotes (otherwise if you a page with ‘38034’ as slug/post_name, this will be used instead of the page with the ID 38034). And you want to return $classes no matter if you added your own or not.

add_filter('body_class', 'custom_body_class');
function custom_body_class($classes) {
    if (is_page(38034))
        $classes[] = 'new-class';
    return $classes;
}

Leave a Comment

error code: 523