Slugs as breadcrumbs for Pages

Ok, problem solved. I´ll add the script below. Hope it´s useful for someone.

if ( is_page() ) {
            $post = $wp_query->get_queried_object();
            if ( $post->post_parent == 0 ){ echo "<li> &raquo; ".ucwords(str_replace("-", " ", $post->post_name))."</li>"; } 
            else {
                $title = the_title('','', FALSE);
                $ancestors = array_reverse( get_post_ancestors( $post->ID ) );
                array_push($ancestors, $post->ID);

                foreach ( $ancestors as $ancestor ){
                    if( $ancestor != end($ancestors) ){
                        echo '<li> &raquo; <a href="'. get_permalink($ancestor) .'">'. ucwords(str_replace("-", " ", basename(get_permalink($ancestor)))) .'</a></li>';
                    } else {
                        echo '<li> &raquo; '. ucwords(str_replace("-", " ", basename(get_permalink($ancestor)))) .'</li>';
                    }
                }
            }
} // You just missed this bracket, else this is working awesome! 

Leave a Comment