Edit image value in Schema

#323872
  • Resolved Rekain
    Rank Math free

    Hello,

    I added this code in my functions.php to change the url of the product image in the Schema, but it doesn’t work.

    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
    if ( ! is_product() ) {
    return $entity;
    }

    $entity['image'][0]['url'] = 'NEW URL';

    return $entity;
    } );

    I also tried with
    $image = [];
    $image[] = [
    '@type' => 'ImageObject',
    'url' => 'NEW URL',
    'height' => 614,
    'width' => 1080,
    ];
    $entity['image'] = $image;

    but also no success. The returned array is always correct, but in the frontend it will always show the product image which is set in the WordPress backend.
    Your example with changing the brand value works fine..

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for contacting us and sorry for any inconvenience that might have been caused due to that.

    You can edit the following filter to change the data of the images on product pages:

    
    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
        if( ! is_product() ) {
            return $data;
        }
        $data['primaryImage'] = [
            '@type' => 'ImageObject',
            '@id' => 'https://rankmath.com',
            'url' => 'https://rankmath.com',
            'width' => 800,
            'height' => 800
        ];
    
        return $data;
    }, 99, 2);
    

    Hope this helps solve your issues.

    Don’t hesitate to get in touch if you have any other questions.
    ​​​​​​​

    Rekain
    Rank Math free

    Thanks, this worked!

    Hello,

    We are super happy that this issue is already resolved. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind us asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘Edit image value in Schema’ is closed to new replies.