Add Breadcrumb JSON-LD Schema Markup without Plugins

Add JSON-LD schema markup without using any plugin, If you are add post on category or single child category then this code will worked on your website.

Example

Single category added on post like this
http://thekroyaard.com/how-to/add-schema-structure.html

Single child category added on post like this
http://thekroyaard.com/how-to/wordpress/add-schema-structure.html

But given JSON-LD schema markup’s code will work like http://thekroyaard.com/how-to/add-schema-structure.html .

Code

<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [{
"@type": "ListItem",
"position": 1,
"name": "Home",
"item": "<?php echo get_site_url(); echo '/';?>"
},
{
"@type": "ListItem",
"position": 2,
"name": "<?php
$cat = get_the_category();
$parentCatName = get_cat_name($cat[0]->parent);
if ($cat[0]->category_parent){
echo $parentCatName;
}
else {
echo $cat[0]->cat_name;}
?>",
"item": "<?php
$cat = get_the_category();
$parentCatLink = get_category_link($cat[0]->parent);
$categoryLink = get_category_link($cat[0]->cat_ID );
if ($cat[0]->category_parent){
echo $parentCatLink;
}
else {
echo $categoryLink;
}
?>"},
{
"@type": "ListItem",
"position": 3,
"name": "<?php the_title(); ?>"
}]
}
</script>

How to Do

  • Open Active theme’s folder.
  • Then create folder and make any php file there.
    (example – schema_breadcrumb.php)
  • Paste given code on schema_breadcrumb.php and SAVE.
  • Now open header.php and paste given code when you want to show breadcrumb schema only on post/single.php.
<?php
if(is_single() ) {
include 'template-parts/header/schema_breadcrumb.php';
}
?>

Add location of schema_breadcrumb.php

  • Then SAVE header.php and check your breadcrumb schema markup using schema validator.

Hope you can understand this article and easily add breadcrumb schema markup on your WordPress’s website. Thanks for reading this article.