if (!function_exists('mh_newsdesk_breadcrumbs')) {
function mh_newsdesk_breadcrumbs() {
if (!is_home() && !is_front_page()) {
global $post;
$mh_newsdesk_options = mh_newsdesk_theme_options();
if ($mh_newsdesk_options['breadcrumbs'] === 'enable') {
$position = 1;
echo '
';
// Home link
echo '- ';
echo '';
echo '' . __('Home', 'mh-newsdesk') . '';
echo '';
echo '
';
$position++;
// Post, page, or archive context
if (is_single() && get_post_type() === 'post' && !is_attachment()) {
$category = get_the_category();
if (!empty($category)) {
$cat = $category[0];
echo '- ';
echo '';
echo '' . esc_html($cat->name) . '';
echo '';
echo '
';
$position++;
}
// Current post title (not a link)
echo '- ';
echo '' . get_the_title() . '';
echo '';
echo '
';
} elseif (is_page()) {
// Parent pages
if ($post->post_parent) {
$ancestors = array_reverse(get_post_ancestors($post->ID));
foreach ($ancestors as $ancestor) {
echo '- ';
echo '';
echo '' . get_the_title($ancestor) . '';
echo '';
echo '
';
$position++;
}
}
// Current page title
echo '- ';
echo '' . get_the_title() . '';
echo '';
echo '
';
} elseif (is_category()) {
$cat = get_queried_object();
if ($cat->parent !== 0) {
$parent_cats = get_category_parents($cat->parent, true, '|||');
$parent_parts = explode('|||', trim($parent_cats, '|||'));
foreach ($parent_parts as $parent_cat_name) {
if (!empty($parent_cat_name)) {
echo '- ';
echo '' . strip_tags($parent_cat_name) . '';
echo '';
echo '
';
$position++;
}
}
}
echo '- ';
echo '' . single_cat_title('', false) . '';
echo '';
echo '
';
} elseif (is_search()) {
echo '- ';
echo 'Search results for "' . get_search_query() . '"';
echo '';
echo '
';
} elseif (is_404()) {
echo '- ';
echo 'Page not found';
echo '';
echo '
';
} elseif (is_archive()) {
echo '- ';
echo '' . post_type_archive_title('', false) . '';
echo '';
echo '
';
}
echo '
';
}
}
}
}