'To delete a class name 'page' from the body

I have created a Page Templates in WordPress. The body comes in the class as the following image. I want to remove 'page' class.

enter image description here



Solution 1:[1]

You can add or remove class from body tag with the help of filter. try below script.

function remove_body_classes( $wp_classes ) {
    $blacklist = array( 'page' );
    $wp_classes = array_diff( $wp_classes, $blacklist );
    return $wp_classes;
}
add_filter( 'body_class', 'remove_body_classes', 10, 2 );

Solution 2:[2]

You should add this script at the end of the Page Template that you have created .

<script type="text/javascript">
             $=jQuery;
           $(document).ready(function(){
        $( "body" ).removeClass( "page" )
    });
 </script>

Solution 3:[3]

Filter body_class using array_search as follow works for me:

add_filter( 'body_class', function( $classes ) {
    unset($classes[array_search('page', $classes)]);
    return $classes;
});

Solution 4:[4]

add_filter( 'body_class', function( $classes ) {
    if ( isset( $classes['page'] ) ) {
        unset( $classes['page'] );
    }
    return $classes;
});

Solution 5:[5]

Sorry, I wanted to do the particular for the one page.I have manually adopted the solution which is as follows.The directory path in my condition was wrong

function remove_body_classes( $wp_classes ) {
    if ( is_page_template( 'inc/home-template-page.php' ) ) {
        $page = array( 'page' );
        $wp_classes = array_diff( $wp_classes, $page );
    }
    return $wp_classes;
}
add_filter( 'body_class', 'remove_body_classes', 10, 2 );

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vimal Usadadiya
Solution 2 eli
Solution 3 Tyler2P
Solution 4 Neal Developer
Solution 5 utsav tilava