So, I am trying to use breadcrumbs underneath my navigation, but with no luck.
I am following this tutorial but when I start browsing into my custom post types, it goes wrong.
For example - I have Products - Split into internal and external products on my navigation. When I navigate to one of these - I get the following:
Home » External Products
Which is great!
Now - Inside 'External Products' are sub categories, and inside the sub categories are the products.
If I go to:
Home - External Products - Category 1
I would expect to see:
Home » External Products » Category 1:
but instead see:
Home » Products.
Is there a plugin - or any other way to get around this, maybe even set up paths myself?
I know this may be a little late, but just in case you haven't solved this yet, I've written a breadcrumb function that you may be interested in.
After writing a few WordPress sites and themes and constantly needing a breadcrumb function, we decided to create a reusable one that has support for any custom post type and taxonomy.
Simply drop the code in your functions.php
file and call the function in your theme's templates files wherever you'd like to display the breadcrumb!
If you need any help at all, let me know.
Thanks,
Adam
For custom post type there are 3 main templates
so you can add breadcrumbs without using any plugin. Below is code with schema markup which will help you boost SEO ranking
For archive page:
<ol itemscope itemtype="http://schema.org/BreadcrumbList">
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<meta itemprop="position" content="1"/>
<a itemscope itemtype="http://schema.org/Thing" itemprop="item" href="https://your-domain-name.com/post-type-name">
<span itemprop="name">Post type product(for eg:)</span>
</a>
</li>
</ol>
For taxonomy page:
<div class="breadcrumbs">
<ol itemscope itemtype="http://schema.org/BreadcrumbList">
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<meta itemprop="position" content="1"/>
<a itemscope itemtype="http://schema.org/Thing" itemprop="item" href="https://youdomain/products">
<span itemprop="name">Products</span>
</a>
</li>
>
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<meta itemprop="position" content="2"/>
<a itemscope itemtype="http://schema.org/Thing" itemprop="item" href="<?php echo esc_attr(get_term_link($term, $cat)); ?>">
<span itemprop="name">
<?php
$categories = single_term_title("", false);
echo $categories;
?> category name
</span>
</a>
</li>
</ol>
</div>
for single page:
<div class="breadcrumbs">
<ol itemscope itemtype="http://schema.org/BreadcrumbList">
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<meta itemprop="position" content="1"/>
<a itemscope itemtype="http://schema.org/Thing" itemprop="item" href="https://yourdomain.com/products">
<span itemprop="name">Products</span>
</a>
<span class="breadcrumb-arrow">
>
</span>
</li>
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<meta itemprop="position" content="2"/>
<?php
$cat_name = 'your-taxonomy';
$categories = get_the_terms( $post->ID, $cat_name );
foreach($categories as $category) :
if(!$category->parent): ?>
<span>
<a itemscope itemtype="http://schema.org/Thing" itemprop="item" href="<?php echo esc_attr(get_term_link($category, $cat_name)); ?>">
<?php echo $category->name; ?>
</a>
</span>
<span class="breadcrumb-arrow">
>
</span>
<?php endif; ?>
</li>
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<meta itemprop="position" content="3"/>
<?php
endforeach;
foreach($categories as $category) :
if($category->parent): ?>
<?php echo $category->name; ?>
<?php endif;
endforeach;
?>
</li>
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<meta itemprop="position" content="4"/>
<span class="subcat trim-hc-b-title" title="<?php echo the_title(); ?>">
<?php the_title();?>
</span>
</li>
</ol>
</div>
</div>