Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

<?php

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?

share|improve this question
    
Have you tried a later priority, eg. 11 instead of 10? –  toscho 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

1 Answer 1

up vote 2 down vote accepted

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 );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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