• Resolved gale13

    (@gale13)


    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.

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Brecht

    (@brechtvds)

    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,
    Brecht

    Thread Starter gale13

    (@gale13)

    Hi,

    I want to add terms About and Mentions, and some info about the author.

    Plugin Author Brecht

    (@brechtvds)

    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

    Thread Starter gale13

    (@gale13)

    Hi, I don’t think it work. The schema markup is still the same

    Plugin Author Brecht

    (@brechtvds)

    What is the exact code you’ve added and where did you add it?

    Thread Starter gale13

    (@gale13)

    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 );

    Thread Starter gale13

    (@gale13)

    I add it in the functions.php

    Plugin Author Brecht

    (@brechtvds)

    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() );

    Thread Starter gale13

    (@gale13)

    Hi, it works. Thanks for that. But there are two same terms when I run the code

    'alumniOf' => array(                
    '@type' => 'Organization',
    'name' => 'Cooking School'
    Plugin Author Brecht

    (@brechtvds)

    Could you clarify what you mean by “there are two same terms”?

    Thread Starter gale13

    (@gale13)

    You can see this screen shot of the schema to know what I mean: https://postimg.cc/fVwvh8Pw

    Plugin Author Brecht

    (@brechtvds)

    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?

    Thread Starter gale13

    (@gale13)

    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 );
    Plugin Author Brecht

    (@brechtvds)

    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?

    Thread Starter gale13

    (@gale13)

    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!

Viewing 15 replies - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.