-
-
Save govindak/7435647 to your computer and use it in GitHub Desktop.
wordpress breadcrumbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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>'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php wordpress_breadcrumbs(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment