Skip to content

Instantly share code, notes, and snippets.

@gmarokov
Last active October 22, 2019 06:49
Show Gist options
  • Save gmarokov/e701e985890ea720c2e6644b53403b3e to your computer and use it in GitHub Desktop.
Save gmarokov/e701e985890ea720c2e6644b53403b3e to your computer and use it in GitHub Desktop.
Generate breadcrumbs
<?php
/**
* Generate breadcrumbs
*/
//TODO Translation ready strings
function get_breadcrumb() {
echo '<a href="'.home_url().'" rel="nofollow">Home</a>';
if (is_category() || is_single()) {
echo "&nbsp;&nbsp;&#187;&nbsp;&nbsp;";
echo "Category: ";
the_category(' &bull; ');
if (is_single()) {
echo " &nbsp;&nbsp;&#187;&nbsp;&nbsp; ";
the_title();
}
}
elseif (is_archive()) {
echo "&nbsp;&nbsp;&#187;&nbsp;&nbsp;";
echo the_archive_title();
}
elseif (is_page()) {
echo "&nbsp;&nbsp;&#187;&nbsp;&nbsp;";
echo "Page: " . get_the_title();
}
elseif (is_search()) {
echo "&nbsp;&nbsp;&#187;&nbsp;&nbsp;Search Results for... ";
echo '"<em>';
echo the_search_query();
echo '</em>"';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment