How to add Schema markup to breadcrumbs
I've used the code from this answer in the breadcrumbs, and it works well. I also added Schema.org markup: https://schema.org/BreadcrumbList Please see at the bottom under Microdata, It asks to add this line:
meta itemprop=position content=1 /
under each menu item. I can add it to the home page like this:
ul
lia href=?php echo home_url(); ?/projectsProjects/ameta itemprop=position content=1 //li
?php
$term = get_term_by(slug, get_query_var(term), get_query_var(taxonomy) );
$tmpTerm = $term;
$tmpCrumbs = array();
while ($tmpTerm-parent 0){
$tmpTerm = get_term($tmpTerm-parent, get_query_var(taxonomy));
$crumb = 'lia href=' . get_term_link($tmpTerm, get_query_var('taxonomy')) . '' . $tmpTerm-name . '/a/li';
array_push($tmpCrumbs, $crumb);
}
echo implode('', array_reverse($tmpCrumbs));
echo 'lia href=' . get_term_link($tmpTerm, get_query_var('taxonomy')) . '' . $term-name . '/a/li';
?
but I can't use it for the other pages, because sometimes there is one more breadcrumb, and sometimes there are 2, 3 or 4 additional breadcrumbs.
And if I am adding: under the second breadcrumb, and under the last breadcrumb in the code, like this:
ul
lia href=?php echo home_url(); ?/projectsProjects/ameta itemprop=position content=1 //li
?php
$term = get_term_by(slug, get_query_var(term), get_query_var(taxonomy) );
$tmpTerm = $term;
$tmpCrumbs = array();
while ($tmpTerm-parent 0){
$tmpTerm = get_term($tmpTerm-parent, get_query_var(taxonomy));
$crumb = 'lia href=' . get_term_link($tmpTerm, get_query_var('taxonomy')) . '' . $tmpTerm-name . '/ameta itemprop=position content=2 //li';
array_push($tmpCrumbs, $crumb);
}
echo implode('', array_reverse($tmpCrumbs));
echo 'lia href=' . get_term_link($tmpTerm, get_query_var('taxonomy')) . '' . $term-name . '/ameta itemprop=position content=3 //li';
?
Then it is not displaying correctly on most pages,
Please see the site to understand exactly:
This page has 1 additional breadcrumb:
https://fast-food-near-me.com/location/az/
(Not correct, showing breadcrumb 1 and 3)
This page has 2 additional breadcrumbs:
https://fast-food-near-me.com/location/phoenix/
(Correct, showing breadcrumb 1, 2 and 3)
And this page has 3 additional breadcrumbs:
https://fast-food-near-me.com/location/85003/
(Not correct, showing breadcrumb 1, 2, 2 and 3)
(Additional to the home page, which shows correctly on all pages since it doesn't need a special function)
Until now, I wasn't using the position markup, but I noticed Google Search Console displays an error: missing position.
Your explanation would be very appreciated, thank you very much!
Topic breadcrumb Wordpress
Category Web