Adding Filter Conditionally Per Page ID

It’s important to always return the value in filter callbacks, otherwise it’s like adding the __return_null() callback.

Here’s an example that adds the blog class only to page with ID 40:

add_filter( 'body_class', 'add_blog_to_body_class' );

function add_blog_to_body_class( $classes )
{
    if ( is_page( 40 ) )
        $classes[] = 'blog';

    return $classes;
}