Skip to content

Instantly share code, notes, and snippets.

@govindak
Forked from barbwiredmedia/Functions.php
Created November 12, 2013 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save govindak/7435647 to your computer and use it in GitHub Desktop.
Save govindak/7435647 to your computer and use it in GitHub Desktop.
wordpress breadcrumbs
//Bread crumbs created
function wordpress_breadcrumbs() {
$delimiter = '|';
$currentBefore = '<span class="current">';
$currentAfter = '</span>';
if ( !is_home() && !is_front_page() || is_paged() ) {
echo '<div id="crumbs">';
global $post;
if ( is_page() && !$post->post_parent ) {
echo $currentBefore;
the_title();
echo $currentAfter; }
elseif ( is_page() && $post->post_parent ) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
echo $currentBefore;
the_title();
echo $currentAfter;
}
echo '</div>';
}
}
<?php wordpress_breadcrumbs(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment