Skip to content

Instantly share code, notes, and snippets.

@ben-heath
Created March 14, 2018 20:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ben-heath/18e0f6e9d5c870658b99d1fd4a923a49 to your computer and use it in GitHub Desktop.
Save ben-heath/18e0f6e9d5c870658b99d1fd4a923a49 to your computer and use it in GitHub Desktop.
Short to add breadcrumb
function breadcrumbs() {
global $post;
ob_start();
// Code
if(!is_home()) {
$breadcrumb = '<nav class="breadcrumb">';
$breadcrumb .= '<a href="'.home_url('/').'">Home</a><span class="divider"> / </span>';
if (is_category() || is_single()) {
$breadcrumb .= the_category(' <span class="divider"> / </span> ');
if (is_single()) {
$breadcrumb .= ' <span class="divider"> / </span> ';
$breadcrumb .= the_title();
}
} elseif (is_page()) {
$breadcrumb .= get_the_title();
}
$breadcrumb .= '</nav>';
}
$breadcrumb.= ob_get_contents();
ob_end_clean();
return $breadcrumb;
}
add_shortcode( 'breadcrumbs', 'breadcrumbs' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment