Remove class that has been added by parent theme

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.

Read More
<?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?

Related posts

Leave a Reply

1 comment

  1. 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 );