My parent theme generates the following class in body: style-cupcake. I don't want that. The best way to get rid of this is by adding my own functions in a functions.php file in my child theme, right?

I tried this (a solution I found on WPSE) but it does not seem to work. "custom background" is removed, but style-cupcake persists.


function my_body_class( $wp_classes, $extra_classes )
    // List of the only WP generated classes that are not allowed
    $blacklist = array('custom-background', 'style-cupcake');
    // Blacklist result: (uncomment if you want to blacklist classes)
    $wp_classes = array_diff( $wp_classes, $blacklist );

    // Add the extra classes back untouched
    return array_merge( $wp_classes, (array) $extra_classes );
add_filter( 'body_class', 'my_body_class', 10, 2 );


Any idea?

  • Have you tried a later priority, eg. 11 instead of 10? – fuxia Apr 14 '13 at 16:49
  • @toscho I had not. So, basically what does is: all functions are called with a priority (quickest being 1) and a latter can overwrite a former? Thank you, it works! Please provide your comment as an answer and I'll mark it as correct. – Bram Vanroy Apr 14 '13 at 16:55

If you want to apply a filter to the same content another function has filtered, change the priority argument (which should have been named _execution_order_) to a higher number.

So …

add_filter( 'body_class', 'my_body_class', 11, 2 );

… will make sure my_body_class() will be called after another_body_class() that has been registered with 10:

add_filter( 'body_class', 'another_body_class', 10, 2 );

Also note the priority argument will be used as an array key. It doesn’t have to be a number, just a valid key.

// this works!
add_filter( 'body_class', 'my_body_class', 'very late please', 2 );
add_filter( 'body_class', 'my_body_class', PHP_INT_MAX, 2 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.