I’am using Avante theme for my WP website.
All my posts have two categories : Main category and subcategory
◊ The problem is that my “Main Category” page displays subcategory in breadcrumb, it looks like:
Home > Main Category > Subcategory
And should be:
Home > Main Category
◊ The default breadcrumb function is :
function the_breadcrumb() {
echo '<ul id="breadcrumbs">';
if (!is_home()) {
echo '<li><a href="';
echo home_url();
echo '">';
echo 'Home';
echo '</a></li><li class="separator"> › </li>';
if (is_category() || is_single()) {
echo '<li>';
the_category(' </li><li class="separator"> › </li><li> ');
//PATCH I ADDED IN ORDER TO PREVENT ALPHABETICAL SORTING THAT ALSO DISPLAY THAT DAMNED SUBCATEGORY
/*$cats=get_the_category('');
$cid=array();
foreach($cats as $cat) { $cid[]=$cat->cat_ID; }
$cid=implode(',', $cid);
$numItems = count($cid);
$i = 0;
foreach((get_categories('orderby=id&include='.$cid)) as $category) { // notice orderby
if($i === $numItems) {
echo '<li><a href="'.get_category_link($category->cat_ID).'">'.$category->cat_name.'</a></li>'; // keep a space after </a> as seperator
}else{
echo '<li><a href="'.get_category_link($category->cat_ID).'">'.$category->cat_name.'</a></li><li class="separator"> › </li>'; // keep a space after </a> as seperator
}
$i++;
}*/
if (is_single()) {
echo '</li><li class="separator"> › </li><li>';
the_title();
echo '</li>';
}
} elseif (is_page()) {
if($post->post_parent){
$anc = get_post_ancestors( $post->ID );
foreach ( $anc as $ancestor ) {
$output = '<li><a href="'.get_permalink($ancestor).'" title="'.get_the_title($ancestor).'">'.get_the_title($ancestor).'</a></li> <li class="separator">/</li>';
}
echo $output;
echo '<strong title="'.$title.'"> '.$title.'</strong>';
} else {
echo '<strong> ';
echo the_title();
echo '</strong>';
}
}
}
elseif (is_tag()) {single_tag_title();}
elseif (is_day()) {echo"<li>Archive for "; the_time('F jS, Y'); echo'</li>';}
elseif (is_month()) {echo"<li>Archive for "; the_time('F, Y'); echo'</li>';}
elseif (is_year()) {echo"<li>Archive for "; the_time('Y'); echo'</li>';}
elseif (is_author()) {echo"<li>Author Archive"; echo'</li>';}
elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "<li>Blog Archives"; echo'</li>';}
elseif (is_search()) {echo"<li>Search Results"; echo'</li>';}
echo '</ul>';
}
if ( ! isset( $content_width ) ) $content_width = 980;
?>
◊ On the Subcategory page, the path is correct :
Home > Main Category > Subcategory
And the path is also correct in post page :
Home > Main Category > Subcategory > Title
◊ What can I do to prevent the subcategory to be displayed in the parent category breadcrumb ?
Thank you in advance
Read more here: Breadcrumb display subcategory in parent category page