franciccio-ITALIANO Posted February 25, 2024 Posted February 25, 2024 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? ?
gornycreative Posted February 25, 2024 Posted February 25, 2024 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. 1
franciccio-ITALIANO Posted February 26, 2024 Author Posted February 26, 2024 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?
gornycreative Posted February 26, 2024 Posted February 26, 2024 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?
wbmnfktr Posted February 27, 2024 Posted February 27, 2024 The Snippets module by @teppo is absolutely perfect for this!
Fokke Posted March 1, 2024 Posted March 1, 2024 I just added some structured data to website with blog posts. I used https://github.com/spatie/schema-org library, which covers all schema.org types and their properties. This library was very simple to use. 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now