Archived topic
JSON Markup: How to implement it in some posts.
3 replies · Started by jal-mj on June 14, 2021
Hi,
I'm making some SEO change in some posts. I want to put some faq markup generator in some page. I usually use: https://technicalseo.com/tools/schema-markup-generator/ and then copy de json code (script) at the end of the html post. After that I check it here: https://search.google.com/test/rich-results
The think is that I try the code directly in the tool that google provides and it works well. But when I check the url where the code is, then it says that something is wrong. It shouldn't be happening, but I think come cache tool is making a disorder in the code. Maybe this disorder is caused by generatepress. I'm not really sure.
I would ask you how is the correct way to implement it in generatepress.
Thank you very much.
Hi there,
the Theme doesn't interfere with content added to your post element.
You may find the issue is where the code is being added, as JSON-LD would generally be added to the website header.
One method you can try is:1
1. Create a Custom Field in your post, give it a name and add your <script> to its value.
2. Create a new Hook Element:
https://docs.generatepress.com/article/hooks-element-overview/
2.1 In the Hook Text Area add this code to get the custom field and output it:
<?php
$faq = get_post_meta(get_the_ID(), 'your_custom_field_name', true);
echo $faq;
?>
You will need to change the your_custom_field_name to match your custom field name (key)
2.2 Set the Hook to wp_head
2.3 Set the Display Rules to your requirements eg. Posts > All Posts or the specific posts / pages you will be adding JSON-LD
Thank you David for the idea!
Regards.
You're welcome