Breadcrumb with microdata (scheme.org)

Hello together,

I created a breadcrumb navigation using Microdata. Everything works fine except the content number for itemprop=“position” looks like this:

Start 1 → level 1 → level 2

Can someone please help me and tell me how to do this correctly?

<nav class="d-none d-md-block container" aria-label="breadcrumb">
    <ol itemscope itemtype="https://schema.org/BreadcrumbList" class="breadcrumb">
        <?php foreach($site->breadcrumb() as $crumb): ?>
            <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="breadcrumb-item<?php e($crumb->isActive(), ' active') ?>">
                <a itemprop="item" href="<?php echo $crumb->url() ?>" title="<?php echo kirbytextinline($crumb->title()) ?>">
                    <span itemprop="name"><?php echo kirbytextinline($crumb->title()) ?></span>
                    
                    <meta itemprop="position" content="<?php echo $crumb->depth() ?>">
                </a>
            </li>
        <?php endforeach ?>
    </ol>
</nav>

What is the expected result, given that level 1 and level 2 are not children of home, but on the same level? So given that the expected result is

Start 1 → Level 2 → Level 3

You would have to increment the depth by 1 for all pages but the home page.

<meta itemprop="position" content="<?php echo $crumb->isHomePage() ? $crumb->depth() : $crumb->depth() + 1?>">

1 Like

Hello Sonja,

thank you so much. Works awesome :blush:

Here is my full working code:


    <ol itemscope itemtype="https://schema.org/BreadcrumbList" class="breadcrumb">
        <?php foreach($site->breadcrumb() as $crumb): ?>
            <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="breadcrumb-item<?php e($crumb->isActive(), ' active') ?>">
                <a itemprop="item" href="<?php echo $crumb->url() ?>" title="<?php echo kirbytextinline($crumb->title()) ?>">
                    <span itemprop="name"><?php echo kirbytextinline($crumb->title()) ?></span>
                    
                    <meta itemprop="position" content="<?php echo $crumb->isHomePage() ? $crumb->depth() : $crumb->depth() + 1?>">
                </a>
            </li>
        <?php endforeach ?>
    </ol>