remove_filter( ‘body_class’, ‘twentyeleven_body_classes’ );
Thanks Andrew,
Does this go in my child theme functions.php file? It doesn’t seem to work for me. My functions.php file in its entirety:
<?php
function twentyeleven_child_body_classes( $classes ) {
if ( function_exists( 'is_multi_author' ) && ! is_multi_author() )
$classes[] = 'single-author';
if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) && ! is_page_template( 'my-new-template.php' ) )
$classes[] = 'singular';
return $classes;
}
remove_filter( 'body_class', 'twentyeleven_body_classes' );
add_filter( 'body_class', 'twentyeleven_child_body_classes' );
?>
I tried putting remove_filter() before the function, and after the add as well. My code doesn’t break, but it is not overwriting body_class either.
Yea you can’t just paste it in because your child’s functions.php gets loaded before twentyeleven’s functions.php.
Here’s a good article on overriding parent theme functionality.
http://ottopress.com/2010/wordpress-protip-child-themes/
Since twentyeleven_body_classes() isn’t pluggable you’ll have use add_action(‘after_setup_theme’,’yourfunction’).
If you give it a try for a while and still haven’t got it figured out I’ll give you some copy/paste code but it’ll be more rewarding in the long run to learn this process yourself.
Happy coding!
Thank you good sir.
That is what I needed. I knew the child functions.php was called before so I wasn’t sure how to get my functions to overwrite the other. To remove the body_class from functions in twentyeleven I used
function remove_twentyeleven_body_classes(){
remove_filter('body_class', 'twentyeleven_body_classes');
}
add_action('init', 'remove_twentyeleven_body_classes');
Thanks for your help.
Thank you for this solution!
Any particular reason why twentyeleven_body_classes function is not wrapped with an if statement, like the rest of the functions?
if ( ! function_exists( 'twentyeleven_body_classes' ) ) :
// Code here
endif;