How to add custom body class for each page

Hi,

usally a body page class like “.page-id-1” will be added automatically to each page. I would like do choose an individual class which will be added to the body tag of a certain page. Is this possible?

e.g.
Normally: <body page-id-1>
Would like to have <body page-id-1 myclass>

If this is not possible can you recommend a plugin or code snippet for this demand.

Thanks in advance

Hello,

Here is very extensive tutorial on this topic, I think that you will find there everything that you want to know.

Please feel free to ask any other questions that you might have.

Kind Regards, Roman.

I found following solution based on the page name:

This has to be added to the functions.php of the child theme

function add_slug_body_class( $classes ) {
    global $post;
    if ( isset( $post ) ) {
        $classes[] = $post->post_type . '-' . $post->post_name;
}
    return $classes;
}
add_filter( 'body_class', 'add_slug_body_class' );

Best regards GDG