Skip to content

Instantly share code, notes, and snippets.

@joshapgar
Created September 24, 2018 13:08
Show Gist options
  • Save joshapgar/f46c21fcd2f0529d619b623cf67f144d to your computer and use it in GitHub Desktop.
Save joshapgar/f46c21fcd2f0529d619b623cf67f144d to your computer and use it in GitHub Desktop.
Wordpress Breadcrumbs
/***********************
* BREADCRUMBS
***********************/
function streamlineBreadcrumbs($post, $displayCurrent){
$count = 1;
$postAncestors = get_post_ancestors($post);
$sortedAncestorArray = array();
foreach ($postAncestors as $ancestor){
$sortedAncestorArray[] = $ancestor;
}
krsort($sortedAncestorArray); // Sort an array by key in reverse order
foreach ($sortedAncestorArray as $ancestor){
echo "<a class='breadcrumb-link breadcrumb-link-". $count ."' href='". esc_url(get_permalink($ancestor)) ."' title='". get_the_title($ancestor) ."'>". get_the_title($ancestor) ."</a>";
echo "<span class='breadcrumb-separator'>&gt;</span>";
$count++;
}
if($displayCurrent){ //If TRUE - output the current page title
echo "<span class='breadcrumb-current'>". get_the_title($post) ."</span>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment