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);
}

WordPress Snippet Info

Tested with Wordpress v. 4.7.3
Last Modified: 04.05.2017
Last Reviewed: 04.05.2017
Review Status: Needs Review

How to Remove Unwanted WordPress Classes
4.5 (90%) 16 vote[s]
Please report broken snippets.
Report Broken Snippet

Recent Comments