Theme Author
Tom
(@edge22)
Hi there,
Where are you trying to add that code?
The files in the theme editor are PHP, so you can’t add non-PHP into them easily without opening and closing PHP tags.
You can try this code instead:
add_action( 'wp_footer', function() {
?>
Your code in here
<?php
} );
Then add the code using one of these methods instead of editing the core theme files: https://docs.generatepress.com/article/adding-php/
HI, and thank you so much for your reply. I did as you suggested but got this message:
Don’t Panic
The code snippet you are trying to save produced a fatal error on line 1:
syntax error, unexpected ‘&’
The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.
Please use the back button in your browser to return to the previous page and try to fix the code error. If you prefer, you can close this page and discard the changes you just made. No changes will be made to this site.
This is what I attempted to add:
add_action( 'wp_footer', function() {
?>
<!– JSON-LD markup generated by Google Structured Data Markup Helper. –>
<script type=”application/ld+json”>
{
“@context” : “http://schema.org”,
“@type” : “Product”,
“image” : “https://www.endlesshairextensions.com/wp-content/uploads/2019/01/shutterstock_120599233-Copy-2-Copy-1024×817.jpg”,
“description” : “Buy human hair from our extensive Brazilian Hair, virgin hair & Remy Hair collections and get thicker and fuller hair to achieve those voluminous hair dreams!”,
“brand” : {
“@type” : “Brand”,
“logo” : “https://www.endlesshairextensions.com/wp-content/uploads/2019/01/Endless-Hair-Logo-Trans-Cropped_2_410x-1-1.png”
},
“offers” : {
“@type” : “Offer”,
“price” : “59.99”
}
}
</script>
<?php
} );
Also, you asked before where I was adding the code, in the header theme editor. Is this the correct place? I’m trying to add structured data markup using Google recommended JSON-LD.
Still trying to understand why I can’t.
Jen
Theme Author
Tom
(@edge22)
Instead of adding it in the theme editor, can you try one of these methods?: https://docs.generatepress.com/article/adding-php/
Hi, ok so I can make a plugin and add your
functions (your code you suggested I use) to the plugin file?
Theme Author
Tom
(@edge22)
It’s likely easier to use a plugin like this: https://ww.wp.xz.cn/plugins/code-snippets/
I did use this plugin but it was not effective and I got this message instead:
Don’t Panic
The code snippet you are trying to save produced a fatal error on line 1:
syntax error, unexpected ‘&’
The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.
Please use the back button in your browser to return to the previous page and try to fix the code error. If you prefer, you can close this page and discard the changes you just made. No changes will be made to this site.
This is what I attempted to add:
add_action( ‘wp_footer’, function() {
?>
<!– JSON-LD markup generated by Google Structured Data Markup Helper. –>
<script type=”application/ld+json”>
{
“@context” : “http://schema.org”,
“@type” : “Product”,
“image” : “https://www.endlesshairextensions.com/wp-content/uploads/2019/01/shutterstock_120599233-Copy-2-Copy-1024×817.jpg”,
“description” : “Buy human hair from our extensive Brazilian Hair, virgin hair & Remy Hair collections and get thicker and fuller hair to achieve those voluminous hair dreams!”,
“brand” : {
“@type” : “Brand”,
“logo” : “https://www.endlesshairextensions.com/wp-content/uploads/2019/01/Endless-Hair-Logo-Trans-Cropped_2_410x-1-1.png”
},
“offers” : {
“@type” : “Offer”,
“price” : “59.99”
}
}
</script>
<?php
} );
I tried adding your code again and it did not give me an error, which is great. How do I know that it works? When I run the Google structured test tool, the same error shows that prompted me to try to add the code to the themes editor originally so I’m not sure that I have been able to resolve the original issue in the end.
Seems Elementor does not support schema markup yet so there is an error that Google shows and prevents the markup. I was hoping that adding the code directly to the themes editor would be a workaround.
Thoughts?
And thank you for your help!
Theme Author
Tom
(@edge22)
What’s the error you’re getting that’s prompting you to add that code?
This is a screenshot of the error from the Google Structured Data Tool:
https://snag.gy/52MalH.jpg
What do you think??
sorry, meant to include this one as well:
https://snag.gy/Qbm9P1.jpg
Theme Author
Tom
(@edge22)
Can you take a screenshot of the actual warning? It looks like it’s further down the page.
Let me know 🙂
HI, here is a screenshot of the actual warning.
https://snag.gy/JBG2rz.jpg
Theme Author
Tom
(@edge22)
So this is happening because GeneratePress uses the CreativeWork name to be as compatible as possible with all content.
Something in your content is using reviewRating, which isn’t compatible with CreativeWork.
The part of your content that is using reviewRating should have a container which sets the itemtype as something that’s compatible with reviewRating.
You could make it so GP doesn’t use CreativeWork and uses something compatible with reviewRating, but doing this will likely cause more errors, as your content will be missing other required things.
How are you adding the element that’s set as a reviewRating?
Elementor Technical Support told me that I had to remove the Star Rating widget. but this would remove the website reviews. The error you see in the Google structured tool is basically all the text on the landing page.
?