WordPress Snippets at WPcustoms

Clean up and customize body_class

This is a great way to filter out many of the unwanted css classes added. Add your own classes via the $whitelist variable.

 * Snippet Name: Clean up and customize body_class
 * Snippet URL: https://wpcustoms.net/snippets/clean-up-and-customize-body_class/
  function wpc_body_class($wp_classes, $extra_classes)
    // List of classes allowed
    $whitelist = array('my_custom_class', 'another-class');
    $wp_classes = array_intersect($wp_classes, $whitelist);
    return array_merge($wp_classes, (array) $extra_classes);
add_filter('body_class', 'wpc_body_class', 10, 2);