I like working with parent- und childpages, since it holds a better overview in your backend, aswell pushes SEO, by defining dependencies between your pages.
Many WordPress Themes are using Breadcrumbs as a kind of Navigation and overview for the page visitor. These Breadcrumbs rarely link to parent pages, so I found a way to make a Breadcrumb appear like this:
I edited the file theme/includes/breadcrumbs.php of my ElegantTheme Foxy – I don’t know whether this will work with other themes as good as with ET Themes.
HowTo:
Locate the line looking familar to this:
1 |
<a class="breadcrumbs_home" href="<?php echo esc_url( home_url() ); ?>">< ?php esc_html_e('Home','Foxy') ?></a> <span class="raquo">»</span> |
This adds the Home-link aswell as a little arrow between the different links in our Breadcrumb (.raquo).
After this line the ET Breadcrumb should look like this: Home >
Now we want to add the parent page link. BUT… of course we want to link it only then, when there is one 😉
1 |
< ?php if($post->post_parent) { |
If there is one – let’s detect it’s name and permalink:
1 2 |
$parent_link = get_permalink($post->post_parent); $parent_title = get_the_title($post->post_parent);?> |
Next just add a link to the Breadrcrumb and finally also the next arrow (the one between parent- and childpage):
1 2 3 |
<a id="bread_parent_link" href="<?php echo $parent_link; ?>">< ?php echo $parent_title; ?></a> <span class="raquo">»</span> < ?php } ?> |
That’s it! Now we made our ElegantThemes Breadcrumbs showing Parent Pages!
Leave your comment if you need any further help 😉
As luck would have it, I’m looking for this exact solution in the same theme! I tried adding the code above however and got errors. Could you possibly give the code for the entire file? Thanks so much for your help!
Hi Angela,
I’m afraid I don’t have the complete file anymore. But maybe I can determine your problem when you give me your code and the exact error message. Furthermore just check out the Elegant Themes Support Forum, most of the time they give you quick and helpful answers.
Greetings,
Max
Thanks for your reply, Max! I checked Elegant Themes support forum and they’ve said they don’t provide the level of support this customization would require.
I’m not super well-versed in PHP and tried inserting the code above:
<a href="“ class=“breadcrumbs_home“> »
< ?php if($post->post_parent) {
$parent_link = get_permalink($post->post_parent);
$parent_title = get_the_title($post->post_parent);?>
< ?php echo $parent_title; ?>
»
< ?php } ?>
"
<?php
if ( 'listing' == get_post_type() ) {
$categories = get_the_terms( get_the_ID(), 'listing_type' );
if ( $categories ) {
foreach( $categories as $category ) {
$catlink = get_term_link( $category );
echo ('‚.esc_html($category->name).‘ ‚.’» ‚);
break;
}
}
} else {
$category = get_the_category();
if ( $category ) {
$catlink = get_category_link( $category[0]->cat_ID );
echo (‚‚.esc_html($category[0]->cat_name).‘ ‚.’» ‚);
}
}
echo get_the_title();
?>
parent;
$et_term_taxonomy = $et_term->taxonomy;
while ( $et_term_parent_id ) {
$et_current_term = get_term( $et_term_parent_id, $et_term_taxonomy );
$et_taxonomy_links[] = ‚name ) . ‚“>‘ . esc_html( $et_current_term->name ) . ‚‚;
$et_term_parent_id = $et_current_term->parent;
}
if ( !empty( $et_taxonomy_links ) ) echo implode( ‚ » ‚, array_reverse( $et_taxonomy_links ) ) . ‚ » ‚;
echo esc_html( $et_term->name );
?>
get_queried_object();
?>
nickname; ?>
»
Thanks so much for your help!
Sorry, not sure if it pasted correctly above.
<a href="“ class=“breadcrumbs_home“> »
< ?php if($post->post_parent) {
$parent_link = get_permalink($post->post_parent);
$parent_title = get_the_title($post->post_parent);?>
< ?php echo $parent_title; ?>
»
< ?php } ?>
"
<?php
if ( 'listing' == get_post_type() ) {
$categories = get_the_terms( get_the_ID(), 'listing_type' );
if ( $categories ) {
foreach( $categories as $category ) {
$catlink = get_term_link( $category );
echo ('‚.esc_html($category->name).‘ ‚.’» ‚);
break;
}
}
} else {
$category = get_the_category();
if ( $category ) {
$catlink = get_category_link( $category[0]->cat_ID );
echo (‚‚.esc_html($category[0]->cat_name).‘ ‚.’» ‚);
}
}
echo get_the_title();
?>
parent;
$et_term_taxonomy = $et_term->taxonomy;
while ( $et_term_parent_id ) {
$et_current_term = get_term( $et_term_parent_id, $et_term_taxonomy );
$et_taxonomy_links[] = ‚name ) . ‚“>‘ . esc_html( $et_current_term->name ) . ‚‚;
$et_term_parent_id = $et_current_term->parent;
}
if ( !empty( $et_taxonomy_links ) ) echo implode( ‚ » ‚, array_reverse( $et_taxonomy_links ) ) . ‚ » ‚;
echo esc_html( $et_term->name );
?>
get_queried_object();
?>
nickname; ?>
»
I don’t know whether ET updated anything regarding the breadcrumbs, but in your code seems the breadcrumbs_home class to be missing. Your code looks a bit different.
Try adding only the 2-3 code snippets in the correct order as stated in my article. Sidenote, I just noticed my encoding got damaged, so > means the symbol >, and < <.