Skip to content

Instantly share code, notes, and snippets.

@mikeselander
Created August 13, 2014 22:36
Show Gist options
  • Save mikeselander/0fc7e207f12feaee8634 to your computer and use it in GitHub Desktop.
Save mikeselander/0fc7e207f12feaee8634 to your computer and use it in GitHub Desktop.
Nice, clean breadcrumb function
function otm_breadcrumb(){
global $post;
$trail = '';
$page_title = get_the_title($post->ID);
if($post->post_parent) {
$parent_id = $post->post_parent;
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) $trail .= $crumb;
} else {
return '';
}
$trail .= $page_title;
$trail .= '';
echo $trail;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment