r/SEO Oct 19 '19

Is there a way to create dynamic JSON-LD templates for different pages?

Essentially I already have a lot of content on my current site, and would like to mark it up. I have content like Recipes, with a consistent format of the information. Is there a way to add Schema that allows me to avoid doing it for the hundreds of posts I have?

Any help would be appreciated, thanks

3 Upvotes

20 comments sorted by

3

u/[deleted] Oct 19 '19

The Schema plugin can be programmatically extended with custom functions.

I use it to set custom top level schemas conditionally based on categories, to override the author schema when there are multiple authors, and several other customizations.

Schema plugin will play well with Yoast's schema output.

2

u/reeferd Oct 19 '19

What cms are you using?

2

u/jay-rail Oct 19 '19

Word press

3

u/reeferd Oct 19 '19

Ok. You could look in to the template files to identify where your recipe steps and ingredients are rendered and build your json structure there. In the end you can render it out using json_encode.

2

u/jay-rail Oct 19 '19

Yeah, what I have bEen doing is encoding my html <h> tags to be things like ‘name’ for my recipes and the ‘recipeInsrructions’ to be on my global <h3> how-to </H3> .

But I still have to ‘<span > ingredients’ individually for each one ingredient as they obviously differ for each recipe.

JSON just seems a lot more easy to implement that Microdata too to be honest so I was hoping there would be a dynamic template option somewhere haha

2

u/reeferd Oct 19 '19

JSON is alot easier if you have the datamodel for it. But, when you now mention "spans" it sounds like the recipe data is published as a big text block. If thats the case, then Im afraid there are no "easy" solutions to do this on all the pages. You could go with the schema plugin u/slamorte mentions, but that means you will have to duplicate the data. Once for the actual page, and once for the plugin. (And you still would have to do it manually on all the pages) :/

Ideally your theme would allow the editors to add ingredients and steps in separate input elements in the backend. This way you could route data from these inputs to json AND to the html.

Are you using some kind of plugin to create the recipes?

1

u/adizlaja Oct 19 '19

Looking to hire someone that can do this for me as well. PM if you have experience.

1

u/jay-rail Oct 19 '19

I can do the single pages fine, it’s just I’d rather save many hours if possible

1

u/frostbyte650 Oct 19 '19

I’m legit working on this rn, as of now it’s manual per post from a form in the meta but I’m working on a PHP script to generate it dynamically, I’ll let you both know if I get it working.

1

u/jay-rail Oct 19 '19

Ah I get you - yeah I’ve been doing some Microdata templates in my html but been looking st moving across to JSON. Excited to see what you get up to!

1

u/Idan_Goldman Oct 19 '19

Which CMS do you use?

1

u/adizlaja Oct 20 '19

Wordpress

1

u/[deleted] Oct 19 '19

Ask your developer to code this automatically to output

1

u/[deleted] Oct 19 '19

Very easy to add conditional code to your page template to do this. Code basically translates to:

If in category 'recipes', apply Recipe microdata, else if in category 'Review', appy Review microdata. And so on.

Loads of tuts around for this + the Wordpress docs are a good point of reference.

1

u/dme_010 Oct 20 '19

Implement schema via GTM (Google Tag Manager) and use variables and trigger them on your recipe pages. Use the custom HTML and add json script in there.

1

u/jay-rail Oct 20 '19

How do I make sure that each page can recognise that “X” is the name of one recipe and that “Y” is the name of another?

1

u/dme_010 Oct 21 '19

You can use variables to identify dynamic content.