<?php
/**
* functions/inc-breadcrumbs.php
*
* Breadcrumbs for Blog, Pages, WC account Pages
*
* @author JJROD Framework
* @see https://docs.jjrod.com
* @version 1.0
*/
function get_breadcrumb() {
$shop_page_url = get_permalink( wc_get_page_id( 'shop' ) );
echo '<a href="'.$shop_page_url.'" rel="nofollow">Catalog</a>';
if (is_category() || is_single()) {
echo "  / ";
the_category(' • ');
if (is_single()) {
echo "  / ";
$categories = get_the_category();
$category = $categories[0];
echo '<a href="' . get_category_link($category) . '">' . $category->name . '</a>';
echo "  / ";
the_title();
}
} elseif (is_account_page()) {
global $wp;
echo "  / ";
echo '<a href="' . home_url('/my-account/') . '">My Account</a>';
// Check if it's an endpoint and add it to the breadcrumb
$current_endpoint = WC()->query->get_current_endpoint();
if (!empty($current_endpoint)) {
echo "  / ";
echo ucwords($current_endpoint);
}
}
elseif (is_page()) {
echo "  / ";
global $post;
if ($post->post_parent) {
$parent_page = get_post($post->post_parent);
echo '<a href="' . get_permalink($parent_page) . '">' . get_the_title($parent_page) . '</a>';
echo "  / ";
}
echo the_title();
} elseif (is_search()) {
echo "  / Search Results for... ";
echo '"<em>';
echo the_search_query();
echo '</em>"';
} elseif (is_account_page()) {
global $wp;
echo "  / ";
echo '<a href="' . home_url('/my-account/') . '">My Account</a>';
// Check if it's an endpoint and add it to the breadcrumb
$current_endpoint = WC()->query->get_current_endpoint();
if (!empty($current_endpoint)) {
echo "  / ";
echo ucwords($current_endpoint);
}
}
}
/**************** END ****************
** END Generate breadcrumbs
**************** END ***************/
PHP