Steps
- Add the PHP code to your theme’s
functions.php. - Save the changes.
- Open any single blog post.
- WordPress will add the
custom-blog-postclass to the<body>element.
/**
* Add a custom body class to single blog posts
*/
function custom_post_body_class( $classes ) {
if ( is_single() && get_post_type() === 'post' ) {
$classes[] = 'custom-blog-post';
}
return $classes;
}
add_filter( 'body_class', 'custom_post_body_class' );
Tested on
WordPress 6.8
Reported by the author on October 1, 2026. WPFolks has not verified this.
Not tested against WordPress 7.1.3. It may still work.