Jump to content

SEO PRACTICE: How to insert json-ld structured data


Recommended Posts

Hi, through this site I generated a json-LD code for page definition from SEO point of view. They say that this language is the last frontier and better than RDF language. So I would like to understand how to integrate it with processwire.
Integrating html meta tags with php language in processwire is easy and painless. I didn't understand if I can do the same thing with a json language.
So the suggested scheme is this:

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Article",
  "headline": "",
  "image": "",  
  "author": {
    "@type": "",
    "name": ""
  },  
  "publisher": {
    "@type": "Organization",
    "name": "",
    "logo": {
      "@type": "ImageObject",
      "url": ""
    }
  },
  "datePublished": ""
}
</script>

Through the wireinclude function the template could link to a .php file with this .json code in it, however with processwire/php strings in it. In this way:

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Article",
  "headline": "<?=$page->title?>",
  "image": "",  
  "author": {
    "@type": "",
    "name": "<?=$page->name_author?>"
  },  
  "publisher": {
    "@type": "Organization",
    "name": "<?=$page->name_site?>",
    "logo": {
      "@type": "ImageObject",
      "url": ""
    }
  },
  "datePublished": "<?=$page->date_article?>"
}
</script>

Can it be done or is it a mess? ?

 

Link to comment
Share on other sites

Yes. I actually tie this in with custom page classes, because often the page class matches a structured content type.

When I am building a site that is using a repeater block system, there are three 'tracks' of data that get pulled in: structured data, page data and presentation data.

Usually structured data is a php file that outputs json.

Page data is a php file that does whatever calculations I need for a content block and passes a special latte variable into the latte variable array.

Presentation data ties together the structured data and bring in a special computed variable from the latte variables I have set.

This way the structured data logic, data cleaning prep logic and presentation logic remain separate.

  • Like 1
Link to comment
Share on other sites

18 hours ago, gornycreative said:

Yes. I actually tie this in with custom page classes, because often the page class matches a structured content type.

When I am building a site that is using a repeater block system, there are three 'tracks' of data that get pulled in: structured data, page data and presentation data.

Usually structured data is a php file that outputs json.

Page data is a php file that does whatever calculations I need for a content block and passes a special latte variable into the latte variable array.

Presentation data ties together the structured data and bring in a special computed variable from the latte variables I have set.

This way the structured data logic, data cleaning prep logic and presentation logic remain separate.

OK, but then the second version of the schema I set up, where the processwire code strings are integrated into the json structure, IS CORRECT?

Link to comment
Share on other sites

Yes. You can use php to output all sorts of content and processwire allows you to submit headers as well. But in your case, yes, you can use php and the API to output a json-ld structured data block.

There's a module someone built already if you want to see examples, plus I think maybe RockFrontend includes a structured data option too?

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...