Lucky Singh
Lucky Singh

Reputation: 1

How to skip JSON-LD Data Structure from Blogger Template and Use the Structure Present on Post Page

I have added a NewsArticle Data Structure JSON-LD in the Template file of my Blogger Site. I want that JSON-LD to not work if there is a JSON-LD already present on the Post Page.

  1. I have a blog based on Blogger platform. The below code is present in main Template file. Since, my website is related to News Articles, I have used this type of Structured Data Markup.
 <b:includable id='postMeta' var='post'>
<b:if cond='!data:view.isPage'>

  <script type='application/ld+json'>
    {
      "@context": "https://schema.org",
      "@type": "NewsArticle",
      "mainEntityOfPage": {
        "@type": "WebPage",
        "@id": "<data:post.url.canonical.jsonEscaped/>"
      },
      "headline": "<data:post.title.jsonEscaped/>",
      "description": "<data:post.snippets.short.jsonEscaped/>",
      "image": ["<data:post.featuredImage.jsonEscaped/>"],
      "datePublished": "<data:post.date.iso8601.jsonEscaped/>",
      "dateModified": "<data:post.lastUpdated.iso8601.jsonEscaped/>",
      "author": {
        "@type": "Person",
        "name": "<data:post.author.name.jsonEscaped/>",
        "url": "<data:post.url.canonical.jsonEscaped/>"
      },
      "publisher": {
        "@type": "Organization",
        "name": "<data:blog.title/>",
        "logo": {
          "@type": "ImageObject",
          "url": "https://lh3.googleusercontent.com/ULB6iBuCeTVvSjjjU1A-O8e9ZpVba6uvyhtiWRti_rBAs9yMYOFBujxriJRZ-A=h60",
          "width": 206,
          "height": 60
        }
      }
    }
  </script>
</b:if>
</b:includable>
  1. On my blog, there also are Job Posts. For that I have added the JobPosting type structured JSON script to the individual post page using Post Editor - HTML View.

  2. When I tested a Job Post using Rich Results Test, it detected both the Data Structures that is Articles as well as Job Postings. image from result generated for a job post

  3. What I wanted was that it should take only single Data Structure i.e. if on a Post Page a JSON-LD Script is already present than the NewsArticle JSON-LD present in the main template shall not operate.

  4. For doing this I made the following changes in the code that I shared in Point 1 -

<b:if cond='!data:view.isPage'>

  <b:if cond='data:post.jsonLd'>
    <b:eval var='postJson' expr='data:post.jsonLd' />
    <script type='application/ld+json'><data:post.jsonLd/></script>
  <b:else/>

    <script type='application/ld+json'>
      {
        "@context": "https://schema.org",
        "@type": "NewsArticle",
        // other properties....
}

But still, both the data structures are getting crawled.

What should I do to achieve this purpose? I simply want that the NewsArticle Data Structure JSON-LD shall not operate if another JSON-LD is already present on the Post Page.

P.S - If you are thinking that why don't I remove the NewsArticle JSON-LD from the Template file, then I should tell you that I can't do this because there is already 100+ News Articles present on the blog and if I remove the JSON-LD for news articles from the main template than I will have to manually add the JSON script to each post.

Upvotes: 0

Views: 269

Answers (1)

Atakan Au
Atakan Au

Reputation: 142

This method does not exist: data:post.jsonLd.

There are lots of News Articles. You have fewer Job posts. If so, add a "Job" label to your Job Posts.

Find the code that displays the post content in the template file. It will be similar to:

<!-- Post Body Entry Content-->
<div class='post-body entry-content' id='post-body'>
    <data:post.body/>
</div>

Place the following code after this section:

<b:if cond='data:blog.pageType == "item"'>
    <b:if cond='data:post.labels any (label => label.name == "Job")'>
        <!-- This post has "Job" label. Skip NewsArticle JSON-LD -->
    <b:else/>
        <!-- This post has no "Job" label. Place your NewsArticle JSON-LD -->
        <script type='application/ld+json'>
            {
              "@context": "https://schema.org",
              "@type": "NewsArticle",
              ...
            }
        </script>
    </b:if>
</b:if>

This code adds NewsArticle Data Structure to posts without "Job" label. If the post has the label "Job" it will not contain any extra JSON-LD information.

Upvotes: 0

Related Questions