Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@frensuren
Last active September 2, 2019 06:20
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 frensuren/1f32cccfdcf245d17b6782583dc9ec01 to your computer and use it in GitHub Desktop.
Save frensuren/1f32cccfdcf245d17b6782583dc9ec01 to your computer and use it in GitHub Desktop.
Generate Basic Wordpress Breadcrumb
<?php
/**
* Generate Breadcrumb
*/
function the_breadcrumb() {
if (!is_front_page()) {
// Start the breadcrumb with a link to your homepage
echo '<ol>';
echo '<li><a href="';
echo get_option('home');
echo '">';
bloginfo('name');
echo '</a></li>' ;
// Check if the current page is a category, an archive or a single page. If so show the category or archive name.
if (is_category() || is_single() ){
echo '<li>';
the_category(', ');
echo '</li>';
} elseif (is_archive() || is_single()){
if ( is_day() ) {
printf( __( '%s', 'text_domain' ), get_the_date() );
} elseif ( is_month() ) {
printf( __( '%s', 'text_domain' ), get_the_date( _x( 'F Y', 'monthly archives date format', 'text_domain' ) ) );
} elseif ( is_year() ) {
printf( __( '%s', 'text_domain' ), get_the_date( _x( 'Y', 'yearly archives date format', 'text_domain' ) ) );
} else {
_e( 'Blog Archives', 'text_domain' );
}
}
// If the current page is a single post, show its title with the separator
if (is_single()) {
echo '<li>';
the_title();
echo '</li>';
}
// If the current page is a static page, show its title.
if (is_page()) {
echo '<li>';
the_title();
echo '</li>';
}
// if you have a static page assigned to be you posts list page. It will find the title of the static page and display it. i.e Home >> Blog
if (is_home()){
global $post;
$page_for_posts_id = get_option('page_for_posts');
if ( $page_for_posts_id ) {
$post = get_page($page_for_posts_id);
setup_postdata($post);
echo '<li>';
the_title();
echo '</li>';
rewind_posts();
}
}
echo '</ol>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment