Remove class from body tag in wordpress

Created at 18-Mar-2021 , By samar

Remove class from body tag in wordpress

In this session, we will try our hand at solving the "Remove class from body tag in wordpress".

  • Remove multiple classes from body tag in wordpress

    --PATH wp-content\themes\<yourTheme>\functions.php
    add_filter('body_class', 'remove_body_classes');
    function remove_body_classes( $classes ) { 
        $remove_classes = ['custom-class', 'archive'];
        $classes = array_diff($classes, $remove_classes);
        return $classes;    
    }
    

    If you want to remove any particular class or classes from the body tag in wordpress you can remove it by using array_diff() function. array_diff() function removes the list of items of an array from the given array. You can pass more classes with comma separated values to $remove_classes variable. Just copy/paste code in your functions.php file to remove unwanted classes in wordpress.

  • Remove all nasty classes from body tag

    --PATH wp-content\themes\<yourTheme>\functions.php
    add_filter('body_class','remove_all_class_names');
    function remove_all_class_names($classes) {
        return array();
    }
    

    If you want to remove all classes from body tag in wordpress just add code to your theme's function.php file. It will remove all the nasty classes from your body tag.

  • Remove a single class from body tag in wordpress

    --PATH wp-content\themes\<yourTheme>\functions.php
    add_filter('body_class', 'remove_body_class');
    function remove_body_class( $classes ) {
        $remove_class = ['remove-class'];
        $classes = array_diff($classes, $remove_class);
        return $classes;
    }
    

    Remove a single class from body tag in wordpress, you can use this method to remove a single class from the body in wordpress. You can change the value of $remove_class variable and pass the class name which you want to remove from the page.

Back to code snippet queries related wordpress

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.