X

Setup whitelist body_class to remove unwanted classes

Onetone Review - style

Adding this snippet to the functions.php of your wordpress theme 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 classes added



Code Snippet:


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

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!