Answer the question
In order to leave comments, you need to log in
WordPress: How to make a main post category for breadcrumbs?
The problem itself
I will try to explain clearly. So, I have a theme (RedWaves-Lite) with my own breadcrumbs. But here's the problem - the breadcrumbs just show the first one in the list of "selected headings to post". That is, if I choose "Uncategorized, Android, Something else" as headings for the entry, then it shows "Uncategorized" in breadcrumbs.
How I'm supposed to decide
Perhaps you know the Yoast SEO plugin? So here we can select "Main heading". It is used for its (plugin) breadcrumbs. Well, what if we implement a function from Yoast into a theme? That is, set the "Function" of the "Main heading" in the theme code?
What I found in the course of "research"
After 100 failed attempts, I couldn't do it because I don't have enough knowledge. But I found something that might be helpful:
/*-----------------------------------------------------------------------------------*/
/* Breadcrumbs
/*-----------------------------------------------------------------------------------*/
if (!function_exists('redwaves_breadcrumb')) {
function redwaves_breadcrumb() {
echo '<div><i class="fa fa-home"></i></div> <div typeof="v:Breadcrumb" class="root"><a rel="v:url" property="v:title" href="';
echo home_url();
echo '">'.sprintf( __( "Home","redwaves-lite"));
echo '</a></div><div>'.__('<i class="fa fa-caret-right"></i>','redwaves-lite').'</div>';
if (is_category() || is_single()) {
$categories = get_the_category();
$output = '';
if($categories){
echo '<div typeof="v:Breadcrumb"><a href="'.get_category_link( $categories[0]->term_id ).'" rel="v:url" property="v:title">'.$categories[0]->cat_name.'</a></div><div>'.__('<i class="fa fa-caret-right"></i>','redwaves-lite').'</div>';
}
if (is_single()) {
echo "<div typeof='v:Breadcrumb'><span property='v:title'>";
the_title();
echo "</span></div>";
}
} elseif (is_page()) {
echo "<div typeof='v:Breadcrumb'><span property='v:title'>";
the_title();
echo "</span></div>";
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question