Archived topic
Schema and recipe
7 replies · Started by Mathieu on January 27, 2020
Hi Tom,
I am trying to use the "Recipe" schema with GeneratePress without doing some hardcoding.
I found the "generate_do_microdata" it does seem to work only with some predefined schema and I am not sure how to hook into it.
Also, I want the title itemprop to be "name" instead of headLine? Is there a way?
Regards,
Hi there,
Is Tom's snippet in #1 here what you are looking for?
https://generatepress.com/forums/topic/add-comments-and-user-review-stars-to-a-page-built-with-sections/#post-825096
Let me know :)
Hi Leo,
Yes it worked... Two others related question ;)
1) I would like to be able to filter that line that is in content-single.php
if ( generate_show_title() ) {
the_title( '<h1 class="entry-title" itemprop="headline">', '</h1>' );
}
I want itemprop="name". At least in the case it is a recipe.
2) Is there an internal variable or function that would return me the schema? So that I can know if it's Recipe, CreativeWork, Video, etc... elsewhere in the code.
Kind regards,
Hi there,
You would need to create a child theme and overwrite the entire file to change that, unfortunately.
If it was me, I would opt to go with a JSON-LD solution instead of microdata.
For example: https://wordpress.org/plugins/wpsso-schema-json-ld/
Or more specific to recipes: https://wordpress.org/plugins/wp-recipe-maker/
Then you can disable the theme microdata:
add_filter( 'generate_schema_type', '__return_false' );
Our microdata is filterable, but it's somewhat complex to do with something like recipes - JSON-LD is a way better solution.
Let me know if you need more info :)
Thanks Tom.
I am not really a fan of the JSON solution for different reasons but I'll just filter it out with the generate_show_title filter. I will post my solution for your user when I am done.
One last question. I will need to also filter out the categories at the bottom of the article to add some itemprop in that. What is the tricks?
Kindest regards,
Absolutely - you can use this filter: generate_category_list_output
add_filter( 'generate_category_list_output', function() {
// Your solution here
} );
It worked Tom, thanks a lot.
For those who wants to modify the itemprop of the title without having to overwrite the template file.
add_filter('generate_show_title', function () {
if (is_single() && in_the_loop() && is_main_query()) {
the_title("<h1 class=\"entry-title\" itemprop=\"name\">", "</h1>");
return false;
} else {
return true;
}
});
Have a nice weekend!
Ohh, cool solution! Thanks for sharing :)