Skip to content

Instantly share code, notes, and snippets.

@gabrielizalo
Created July 24, 2017 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielizalo/898714c657fd1a2fe5119fc0f2876483 to your computer and use it in GitHub Desktop.
Save gabrielizalo/898714c657fd1a2fe5119fc0f2876483 to your computer and use it in GitHub Desktop.
Wordpress - Breadcrumb Style Page Titles
// Taken from: https://speckyboy.com/wordpress-snippets-secondary-navigation/
/*
This snippet will check to see if the current page has a parent. If so, the parent page’s link and title are displayed within the H1 tag at the top of the page. An arrow character is also displayed between the parent and current page title to complete the breadcrumb look.
Note that this breadcrumb effect only goes one level deep. So you’ll have to adjust the code if you want to link to multiple levels (Parent » Level 1 » Level 2).
*/
<h1 class="entry-title">
<?php
// Conditional Statement to Check for a Parent Post
if($post->post_parent) {
$parent_title = get_the_title($post->post_parent);
$parent_link = get_page_link($post->post_parent);
// Display Parent Post Link, Title and Separator
echo '<span class="parent-title"><a target="_blank" href="' . $parent_link . '">' . $parent_title . '</a></span>' . '&nbsp;<span class="title-arrow">&#8250;</span>&nbsp; ';
}
// Display the Current Page Title
the_title();
?>
</h1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment