Adding breadcrumbs to non-gallery pages (updated August 2020)

Updated August 2020: I now use the newer Schema.org vocabulary for the breadcrumbs structure instead of the now obsolete data-vocabulary.org. For consistency reasons with my other phplugins tips&tricks, I renamed the my_crumb() helper function. It is now called dlp_my_crumb().

Updated August 9, 2020: Added support for backlight/search.

Backlight provides the option to use breadcrumbs on all gallery pages to simplify navigation. I like to have a common look and feel of my site and prefer to have breadcrumbs on all pages. Thanks to phplugins, this is something that can easily be done:

//Outputs the breadcrumbs for the given page including the home page
function dlp_my_crumb( $page_name ) {
   echo '<ul class="breadcrumbs" itemscope itemtype="https://schema.org/BreadcrumbList"> <li class="fa_pseudo" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a href="/" itemprop="item"><span itemprop="name">Home</span></a> <meta itemprop="position" content="1" /> </li>
<li class="fa_pseudo" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" <span itemprop="name" position="2">'. $page_name .'</span> <meta itemprop="position" content="1" />
</li></ul>';
}

// returns true if $page matches current page or any of its
// sub-pages 
function dlp_page_match($page) {
   if (substr($_SERVER["REQUEST_URI"], 0, strlen($page)) == $page) {
      return true;
   }  else {
     return false;
   }
}

function main_top(){
   // Add breadcrumbs to non-gallery pages
   if (strtolower($this->slug) == 'about') {
      $this->dlp_my_crumb('About');
   } else if (strtolower($this->slug) == 'contact') {
      $this->dlp_my_crumb('Contact');
   } elseif ($this->dlp_page_match('/backlight/search') ) {
      $this->dlp_my_crumb('Search');
   } else if (strtolower($this->slug) == 'xxxx') {
      $this->dlp_my_crumb('Xxxx');
   }
}

Now it is just a matter of adding any other pages you might have with a separate elsif branch inside the main_top test.


Did you like this post? Did you use the given code? Please consider supporting me by buying me a coffee!

Buy Me A Coffee


Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

Web Design Consulting

Do you need help designing your web site or getting Backlight working the way you want? Contact me to discuss your idea or project.


Buy me a Coffee

If you like what I share here, please consider buying me a coffee or a print. This helps keeping me motivated to continue posting. Thank you!

Buy Me A Coffee

Categories