• After a search online for quick and simple breadcrumb code that worked at more than one level depth, I put something together myself. Not having a personal platform to share it online, I am posting it here. It is basic and I’m sure the more experienced users can improve and extend it, but it was sufficient for my needs.

    Enjoy.

    The Code:

    //Check if page has ancestors - if only one parent exists, this will be an empty array
    if($post->ancestors){
    //Reverse the array so out put starts at the top of the hierarchy
    $parents = array_reverse($post->ancestors);
      foreach($parents as $parent){
         echo ' &raquo; <a href="'.get_page_link($parent).'">'.get_the_title($parent).'</a>';
      }
    }
    else if($post->parent){
    //Deal with single parent situation
    echo ' &raquo; <a href="'.get_page_link($post->parent).'">'.get_the_title($post->parent).'</a>';
    }
    //Present current title as simple text, no link
    echo ' &raquo; ';
    the_title();

    You can preface this with a link to the home page to complete the trail.

The topic ‘Breadcrumb Trail for Pages’ is closed to new replies.