Skip to content

Instantly share code, notes, and snippets.

@anwerashif
Last active February 22, 2018 18:46
Show Gist options
  • Save anwerashif/ec4ac740047e2681e616fe2f1c63cbcf to your computer and use it in GitHub Desktop.
Save anwerashif/ec4ac740047e2681e616fe2f1c63cbcf to your computer and use it in GitHub Desktop.
wordpress breadcrumbs
<?php
// Do NOT include the opening PHP tag
/**
* Generate breadcrumbs
*/
function get_breadcrumb() {
echo '<ol class="breadcrumb">';
if (!is_home()) {
echo '<li class="breadcrumb-item">You are here</li>';
echo '<li class="breadcrumb-item"><a href="';
echo get_option('home');
echo '">';
echo 'Home';
echo "</a></li>";
if (is_category() || is_single()) {
echo '<li class="breadcrumb-item">';
the_category(' </li><li class="breadcrumb-item"> ');
if (is_single()) {
echo "</li><li class='breadcrumb-item active'>";
the_title();
echo '</li>';
}
} elseif (is_page()) {
echo '<li class="breadcrumb-item">';
echo the_title();
echo '</li>';
}
}
elseif (is_tag()) {single_tag_title();}
elseif (is_day()) {echo"<li class='breadcrumb-item'>Archive for "; the_time('F jS, Y'); echo'</li>';}
elseif (is_month()) {echo"<li class='breadcrumb-item'>Archive for "; the_time('F, Y'); echo'</li>';}
elseif (is_year()) {echo"<li class='breadcrumb-item'>Archive for "; the_time('Y'); echo'</li>';}
elseif (is_author()) {echo"<li class='breadcrumb-item'>Author Archive"; echo'</li>';}
elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "<li>Blog Archives"; echo'</li>';}
elseif (is_search()) {echo"<li class='breadcrumb-item'>Search Results"; echo'</li>';}
echo '</ol>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment