• Resolved sally

    (@sallyruchman)


    Hello,

    im using the actual Version of Yoast. I have activated Breadcrumbs for my Pages / Posts.

    I have added the code to header.php

    <?php if(!is_front_page()): ?>
    <?php if ( function_exists(‘yoast_breadcrumb’) ) {
    yoast_breadcrumb(‘<p id=”breadcrumbs”>’,'</p>’);
    } ?>
    <?php endif; ?>

    The Breadcrumbs are shown that’s fine. But when checking with Google Structured Data Testing Tool my Pages or Posts, the Breadcrumb Schema is not recognized there.

    Do I need another PHP snippet to achieve this?

    Thx
    Sally

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter sally

    (@sallyruchman)

    Hello,

    still not getting the JSON+LD markup to the breadcrumbs output when checking with Structured Data Tool.
    Can someone give me a hint?

    Thx

    Thread Starter sally

    (@sallyruchman)

    Hello,

    found some script to add to the functions.php, but the Breadcrumbs List Output is still not shown in Google Structured Data Tool

    function crumb_json($crumb){
    $items = array();
    foreach($crumb as $k => $v){
    $items[] = array(
    ‘@type’ => ‘ListItem’,
    ‘position’ => $k+1,
    ‘item’ => array(‘@type’ => ‘WebPage’, ‘@id’ => $v[‘href’], ‘name’ => $v[‘text’])
    );
    }

    $crumb = array(
    ‘@context’ => ‘https://schema.org/&#8217;,
    ‘@type’ => ‘BreadcrumbList’,
    ‘itemListElement’ => $items
    );
    printf(‘<script type=”application/ld+json”>%s</script>’, json_encode($crumb));
    }

    Anyone an Idea how to fix this?

    Thx
    Sally

    Thread Starter sally

    (@sallyruchman)

    ???

    Plugin Support amboutwe

    (@amboutwe)

    Breadcrumb schema is output on content pages, not the homepage. Looking at a few of your content pages, we see breadcrumb schema twice. One set is part of the Yoast schema and the other is likely added with the code you provided above.

    Thread Starter sally

    (@sallyruchman)

    Hello Abboutwe,

    Following Snippet I have in the Header.php:

    <?php if(!is_front_page()): ?>
    <?php if ( function_exists(‘yoast_breadcrumb’) ) {
    yoast_breadcrumb(‘<p id=”breadcrumbs”>’,'</p>’);

    $breadcrumbs = yoast_breadcrumb(”,”,false);
    } ?>
    <?php endif; ?>

    But with the Snippet in Header.php alone checking under google structured data testing the JSON LD Output (BreadcrumbList) is NOT shown.

    To get the correct markup I have to add the following snippet to the functions.php:

    add_filter(‘wpseo_breadcrumb_links’, ‘entex_add_crumb_schema’, 10, 1);
    function entex_add_crumb_schema($crumbs) {

    if( ! is_array( $crumbs ) || $crumbs === array()){
    return $crumbs;
    }

    $last = count($crumbs);
    $listItems = [];
    $j = 1;

    foreach ( $crumbs as $i => $crumb ) {

    $item = [];
    $nr = ($i + 1);

    if(isset($crumb[‘id’])){
    $item = [
    ‘@id’ => get_permalink($crumb[‘id’]),
    ‘name’ => strip_tags( get_the_title( $id ) )
    ];
    }

    if(isset($crumb[‘term’])){
    $term = $crumb[‘term’];

    $item = [
    ‘@id’ => get_term_link( $term ),
    ‘name’ => $term->name
    ];
    }

    if(isset($crumb[‘ptarchive’])){
    $postType = get_post_type_object($crumb[‘ptarchive’]);

    $item = [
    ‘@id’ => get_post_type_archive_link($crumb[‘ptarchive’]),
    ‘name’ => $postType->label
    ];
    }

    /* READ NOTE BELOW: */

    if($nr == $last){
    if(is_author() && !isset($crumb[‘url’])) $crumb[‘url’] = esc_url(get_author_posts_url(get_queried_object_id()));
    }

    /* The ‘text’ indicates the current (last) or start-path crumb (home)*/
    if(isset($crumb[‘url’])) {
    if($crumb[‘text’] !== ”) {
    $title = $crumb[‘text’];
    } else {
    $title = get_bloginfo(‘name’);
    }

    $item = [
    ‘@id’ => $crumb[‘url’],
    ‘name’ => $title
    ];
    }

    $listItem = [
    ‘@type’ => ‘ListItem’,
    ‘position’ => $j,
    ‘item’ => $item
    ];

    $listItems[] = $listItem;
    $j++;
    }

    $schema = [
    ‘@context’ => ‘https://schema.org&#8217;,
    ‘@type’ => ‘BreadcrumbList’,
    ‘itemListElement’ => $listItems
    ];

    $html = ‘<script type=”application/ld+json”>’ . stripslashes(json_encode($schema, JSON_PRETTY_PRINT)) . ‘</script> ‘;
    echo $html;
    remove_filter(‘wpseo_breadcrumb_links’, ‘entex_add_crumb_schema’, 10, 1);
    return $crumbs;
    }

    Why is the JSON LD markup not shown just with the snippet in header.php, why do I have to add a extra code to functions to get the output shown correct, should this not be done from the Yoast Plugin iteslf?

    Checked with Google Structured Data Tool my Content Pages, and see the BreadcrumbList Output just once present, where do you see it twice?

    Thx
    Best regards
    Sally

    Plugin Support amboutwe

    (@amboutwe)

    Using Google’s Structured Data Testing Tool on a post, you will see the first BreadcrumbList and a second BreadcrumbList under the Webpage schema.

    This can also be seen in the source code as shown in this image: https://pasteboard.co/IrV0Wcr.png

    Thread Starter sally

    (@sallyruchman)

    Hello Amboutwe,

    ok, can you please tell me now, how is the correct implementation, that the BreadcrumbList Schema is output in the correct way for Yoast ? Do I need the code above in the functions.php ? Is the Yoast Output under Webpage normally, or should this not be a own Schema Detected like Breadcrumblist?

    Thx
    Sally

    Plugin Support amboutwe

    (@amboutwe)

    To output the breadcrumb schema by Yoast, you do not need to add any code. Simply enable the breadcrumb feature and the plugin will automatically add BreadcrumbList to the combined schema.

    If you want breadcrumbs to be visible on the page, you would need to add code to your theme or use the Yoast breadcrumb shortcode.

    https://kb.yoast.com/kb/implement-wordpress-seo-breadcrumbs/

    Thread Starter sally

    (@sallyruchman)

    thx, ok, I took out the additional code in the functions now, and checked under combined schema where the breadcrumblist is present

    Best regards
    Sally

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Breadcrumbs Structured Data’ is closed to new replies.