Schema ld-json Markup from WPMUDev's Blog Post No Longer Working

Hi. I've implemented schema.org ld-json markup according to https://premium.wpmudev.org/blog/schema-wordpress-seo/ and all was well until by the end of November. Since then, Google Search Console no longer detects the structured data that I added in the "schema" custom field –– unless I implement multiple entities on a single post, in which case the first entity will be ignored and the others will show in the Structured Data Testing Tool. Other readers who followed WPMUDev's blog post tips could be affected. Can you please and help me fix this?

  • Kasia Swiderska

    Hello Alexandre,

    I tested tutorial from the blog post and it still works correctly. I've added one schema ld-json markup for my post and https://search.google.com/structured-data/testing-tool detected it correctly. There was no need for me to add multiple schemas for one post.

    I've checked your site and I can see that php code in header is displaying because it was put between another code with comments. That could be explanation why things are not working correctly.

    Please check your themes header.php file to see if code

    <?php
    $schema = get_post_meta(get_the_ID(), 'schema', true);
    if(!empty($schema)) {
    	echo $schema;
    }
    ?>

    is placed directly before closing </head> tag.

    If you confirm that it is in right place, but schema is still not showing, would you mind allowing support access so we can have a closer look at this?
    To enable support access you can follow this guide here:
    https://premium.wpmudev.org/docs/getting-started/getting-support/#chapter-5

    kind regards,
    Kasia

  • Alexandre

    Hello Kasia and thank you for your reply.

    Thank you also for offering to take a closer look. I just enabled support access.

    The php code for the schema custom field are only in posts where I added schema markup. I placed the code in the header via the Edit page of each of these posts, and the code appears fine when I view the source (except that it seems greyed out (I've removed the comments you mentioned). I left the link to one of these posts in the Support Comment for you to see when you access it.

    So, let me explain in more detail what's happening: On this post, for instance (enxaqueca.com.br/blog/o-que-e-enxaqueca/), you will notice that I have a "schema" custom field with ld-json markup for "Video", followed by "Medical Condition". Before a few weeks ago, Google's Search Console and Structured Data Testing Tool detected both entities as expected. Since then, only "Medical Condition" was detected, even though the "Video" markup is still there. Now, if I repeat the exact same "Video" markup below "Medical Condition" (without deleting the alredy existing one above it), both entities get detected by the Structured Data Testing Tool. It's as if the first markup is being ignored.

  • Kasia Swiderska

    Hello Alexandre,

    There was problem with comments in code that was added before schema. https://search.google.com/structured-data/ was getting "confused" because of those and was not "seeing" the first LD-json lines, so it was recognizing all the scripts after it.

    So this code:

    <meta property="fb:app_id" content="150963641624804" />
    <!-- BEGIN Google Analytics -->
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-1353842-1"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
    
      gtag('config', 'UA-1353842-1');
    <!-- END Global site tag (gtag.js) -->
    
    <!-- BEGIN track pageviews with the default tracker -->
    <!-- SEE https://developers.google.com/analytics/devguides/collection/gtagjs/migration -->
    gtag('config', 'UA-1353842-1');
    <!-- END track pageviews with the default tracker -->
    
    </script>
    <!-- END Google Analytics -->
    
    <!-- BEGIN Facebook Instant Pages -->
    <meta property="fb:pages" content="127284016526" />
    <!-- END -->

    Was culprit. I removed all the comments from it - so lines that are like <!-- END --> - purged cache, changed custom field Schema in example post so it only has one Video and MedicalCondition type and now structured-data tool is seeing it correctly.

    The php code for the schema custom field are only in posts where I added schema markup. I placed the code in the header via the Edit page of each of these posts, and the code appears fine when I view the source (except that it seems greyed out (I've removed the comments you mentioned).

    Field in post you are referring to is only for JS scripts. When you add PHP code into it is displayed as text (you can see it in source of page), it is not interpreted so it is not working. I haven't checked your theme files, but you already have this code added somewhere else because schema is displaying. If you check example post, you will see that I removed code from Header Scripts, but schema is still in source code - there is no need to add this code into that field again.

    kind regards,
    Kasia

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.