WordPress.org

Forums

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

  1. hectorgarrofe
    Member
    Posted 2 years ago #

    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;
    }
  2. esmi
    Forum Moderator
    Posted 2 years ago #

    The body_class filter works fine for me in 3.5

  3. hectorgarrofe
    Member
    Posted 2 years ago #

    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!

  4. hectorgarrofe
    Member
    Posted 2 years ago #

    Any idea?

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

  5. esmi
    Forum Moderator
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic