Can I adjust the schema markup of plugin WP recipe maker
-
Hi, your plugin is great. I love it. But is there any way that I can adjust the schema markup of plugin. I want to add some terms to the schema.
-
Hi there,
Happy to hear you’re enjoying the plugin! We actually have the
wprm_recipe_metadata
filter hook that could be used to alter the recipe schema. Are you familiar with how to use that?What changes are you trying to make specifically?
Kind regards,
BrechtHi,
I want to add terms About and Mentions, and some info about the author.
To give you a specific example, you can do that by adding code like this to your theme’s functions.php file (or as a Code Snippet):
function change_wprm_recipe_metadata( $metadata, $recipe ) {
$author = intval( $recipe->post_author() );
if ( $author ) {
$user = get_userdata( $author );
if ( $user ) {
// Change the author that's used for the metadata.
$metadata['author'] = array( ... );
}
}
return $metadata;
}
add_filter( 'wprm_recipe_metadata', 'change_wprm_recipe_metadata', 10, 2 );Brecht
Hi, I don’t think it work. The schema markup is still the same
What is the exact code you’ve added and where did you add it?
I add this:
function change_wprm_recipe_metadata( $metadata, $recipe ) {
$author = intval( $recipe->post_author );
if ( $author ) {
$user = get_userdata( $author );
if ( $user ) {
// Change the author that's used for the metadata.
$metadata['author'] = array(
'@type' => 'Person',
'@id' => 'https://example.com/author/katie/', // Set the static author URL
'name' => 'Kate', // Set the static name for this example
'url' => 'https://example.com/author/katie/', // Same as @id
'sameAs' => 'https://example.com/', // Website URL
'jobTitle' => 'Home Cook and Food Blogger',
'knowsAbout' => array(
'baking',
'Traditional cuisine',
'Cocktail',
'condiments',
'Dinner meal',
),
'image' => array(
'@type' => 'ImageObject',
'@id' => 'https://example.com/wp-content/litespeed/avatar/d741a7b3b404a37d19ee35042a08cb5e.jpg?ver=1727622785',
'url' => 'https://example.com/wp-content/litespeed/avatar/d741a7b3b404a37d19ee35042a08cb5e.jpg?ver=1727622785',
'caption' => 'Kate',
'inLanguage' => 'en-US'
),
'alumniOf' => array(
'@type' => 'Organization',
'name' => 'Cooking School'
)
);
}
}
return $metadata;
}
add_filter( 'wprm_recipe_metadata', 'change_wprm_recipe_metadata', 10, 2 );I add it in the functions.php
You’re using
$author = intval( $recipe->post_author );
but post_author needs to be a function, as in the example code I gave:$author = intval( $recipe->post_author() );
Hi, it works. Thanks for that. But there are two same terms when I run the code
'alumniOf' => array(
'@type' => 'Organization',
'name' => 'Cooking School'Could you clarify what you mean by “there are two same terms”?
You can see this screen shot of the schema to know what I mean: https://postimg.cc/fVwvh8Pw
I don’t really see how that could be happening. With the filter you are the one altering the output and we don’t change anything about it anymore.
Could you copy and paste the full code you’re using one more time?
Here it is
function change_wprm_recipe_metadata( $metadata, $recipe ) {
$author = intval( $recipe->post_author() );
if ( $author ) {
$user = get_userdata( $author );
if ( $user ) {
// Change the author that's used for the metadata.
$metadata['author'] = array(
'@type' => 'Person',
'@id' => 'https://example.com/author/katie/', // Set the static author URL
'name' => 'Kate', // Set the static name for this example
'url' => 'https://example.com/author/katie/', // Same as @id
'sameAs' => 'https://example.com/', // Website URL
'jobTitle' => 'Home Cook and Food Blogger',
'knowsAbout' => array(
'Gluten-free baking',
'World cuisines',
'Cocktail mixies',
'Homemade condiments',
'Quick meal',
),
'image' => array(
'@type' => 'ImageObject',
'@id' => 'https://example.com/wp-content/litespeed/avatar/d741a7b3b404a37d19ee35042a08cb5e.jpg?ver=1727622785',
'url' => 'https://example.com/wp-content/litespeed/avatar/d741a7b3b404a37d19ee35042a08cb5e.jpg?ver=1727622785',
'caption' => 'Kate',
'inLanguage' => 'en-US'
),
'alumniOf' => array(
'@type' => 'Organization',
'name' => 'Rouxbe Cooking School'
)
);
}
}
return $metadata;
}
add_filter( 'wprm_recipe_metadata', 'change_wprm_recipe_metadata', 10, 2 );I added that exact code on my test site, and shows up as expected. Can you give me a link to where you’ve added that?
I checked. It’s because I already added a code showing author info in each post. But when I use the plugin in a post, it adds the schema of the plugin into the post (no author info). So when I added your code, it duplicated the author info.
Thanks a lot for your help!
- You must be logged in to reply to this topic.