fbpx
How to Remove Unwanted WordPress Classes

How to Remove Unwanted WordPress Classes

This snippet will let you create a white-list of terms to include in body_class. This is a great way to filter out many of the unwanted WordPress css classes added.

Instructions
Add this to your functions.php file.

add_filter('body_class', 'wps_body_class', 10, 2);
function wps_body_class($wp_classes, $extra_classes)
{
    // List of classes allowed
    $whitelist = array('portfolio', 'home', 'error404');
    $wp_classes = array_intersect($wp_classes, $whitelist);
    return array_merge($wp_classes, (array) $extra_classes);
}