- This topic has 7 replies, 3 voices, and was last updated 4 years, 2 months ago by Tom.
-
AuthorPosts
-
January 27, 2020 at 2:08 pm #1146184Mathieu
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,
January 27, 2020 at 5:18 pm #1146298LeoStaffCustomer SupportHi 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-825096Let me know π
January 28, 2020 at 12:45 pm #1147501MathieuHi 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,
January 28, 2020 at 5:14 pm #1147650TomLead DeveloperLead DeveloperHi 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 π
January 29, 2020 at 1:12 pm #1148623MathieuThanks 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,
January 29, 2020 at 4:30 pm #1148737TomLead DeveloperLead DeveloperAbsolutely – you can use this filter:
generate_category_list_output
add_filter( 'generate_category_list_output', function() { // Your solution here } );
February 1, 2020 at 8:18 am #1151396MathieuIt 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!
February 1, 2020 at 10:19 am #1151499TomLead DeveloperLead DeveloperOhh, cool solution! Thanks for sharing π
-
AuthorPosts
- You must be logged in to reply to this topic.