How to add class to body tag of archive page?

Can you tell me how to add a class to the body tag of my archive page? Similar to how we can add classes to pages via ‘edit page’ in wp-admin. I want to do that for archives and single posts.

I can add a class to wp-index.php in my child theme Views -> Renew folder but this adds the class too far down in the DOM to achieve the desired result.

I would like to add it here:
<body class="archive post-type-archive post-type-archive-watch logged-in admin-bar x-renew x-full-width-layout-active x-full-width-active x-post-meta-disabled x-archive-standard-active pro-v1_1_1 x-child-theme-active cornerstone-v2_0_6 customize-support">

Thank you

Hi,

To add a class to the body in archive page, you can add the code below in your child theme’s functions.php file


add_filter( 'body_class', 'custom_class' );
function custom_class( $classes ) {
    if ( is_archive() ) {
        $classes[] = 'my_archive';
    }

   if ( is_singular( 'post' ) ) {
        $classes[] = 'my_single';
    }
    return $classes;
}

For more information kindly refer to the link below.

Hope that helps.