Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- To call the function on the front end use the following:
- <?php
- the_breadcrumbs();
- ?>
- */
- function the_breadcrumbs() {
- $breadcrumb_separator = ' > ';
- if (!is_home()) {
- echo '<a href="' . home_url('/') . '">Home</a><span>' . $breadcrumb_separator . '</span>';
- // Check if we're on a category-based archive page
- if (is_category()) {
- $categories = get_the_category();
- $output = '';
- if ($categories) {
- foreach ($categories as $category) {
- $output .= '<a href="' . get_category_link($category->term_id) . '">' . $category->cat_name . '</a><span>' . $breadcrumb_separator . '</span>';
- }
- echo trim($output, '<span>' . $breadcrumb_separator . '</span>');
- }
- // Check if we're on a date-based archive page
- } elseif (is_date()) {
- if (is_day()) {
- echo '<span>' . get_the_date('F j, Y') . $breadcrumb_separator .'</span>';
- } elseif (is_month()) {
- echo '<span>' . get_the_date('F Y') . $breadcrumb_separator . '</span>';
- } else {
- echo '<span>' . get_the_date('Y') . $breadcrumb_separator . '</span>';
- }
- // Check if we're on a tag-based archive page
- } elseif (is_tag()) {
- $tag = single_tag_title('', false);
- echo '<span>' . $tag . '</span>';
- // Check if we're on a custom post type archive page
- } elseif (is_post_type_archive()) {
- echo '<span>' . post_type_archive_title('', false) . '</span>';
- // Check if we're on a search results page
- } elseif (is_search()) {
- echo '<span>Search Results for "' . get_search_query() . '"</span>';
- } else {
- // For any other page, just display the page title
- the_title();
- }
- } else {
- echo 'Home';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement