A whitelist is a great way to filter out many unwanted classes added in your theme. You can create a whitelist of the terms to include in body_class.
Instructions: Add the following code to the functions.php file of your WordPress theme to set up whitelist body_class
.
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); }
You may also enjoy adding custom body_class using wp_is_mobile.
Comments Leave a Reply