WordPress.org

Support

Support » Alpha/Beta » add_filter('body_class','browser_body_class') breaks my theme

add_filter('body_class','browser_body_class') breaks my theme

  • Here is the function I’ve been using since WP 3.0. to add an ancestor class to my <body>.

    Now in WP 3.5 beta1, this function breaks my theme.

    Any idea?

    add_filter('body_class','browser_body_class');
    
    function browser_body_class($classes = '') {
    
    	global $post;
    
    	$parent = array_reverse(get_post_ancestors($post->ID));
    
    	if($post->post_parent == 0){
    	  $classes[] = 'no-ancestor';
    
    	} else {
    	  $classes[] = 'ancestor-'.$parent[0];
    	}
    
    	return $classes;
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • esmi

    @esmi

    Forum Moderator

    The body_class filter works fine for me in 3.5

    It seems to be a problem with the function name.

    If i use:

    add_filter('body_class','browser_body_class2');
    
    function browser_body_class2($classes = '') {
    	global $post;
    	//Necesitamos saber cual es la pagina de primer nivel.
    	$parent = array_reverse(get_post_ancestors($post->ID));
    
    	if($post->post_parent == 0){ // estem en un primer nivell
    	  $classes[] = 'no-ancestor';
    
    	} else { // estem en un nivell que no es el primer
    	  $classes[] = 'ancestor-'.$parent[0];
    	}
    
    	return $classes;
    }

    Works perfect!

    Any idea?

    There’s a new Worpress function in 3.5 with the same name?

    esmi

    @esmi

    Forum Moderator

    Not that I can find but, FWIW, I usually prefix all of my custom function names with the name of the theme to avoid potential classes. So perhaps that’s why I’ve not had any problem.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘add_filter('body_class','browser_body_class') breaks my theme’ is closed to new replies.
Skip to toolbar