Prioritize Product gallery image as the og:image instead of featured image

#455691
  • Resolved Clairen Jewelry
    Rank Math free

    Hi,

    I want to Prioritize Product gallery image as the og:image instead of featured image.
    I am able to do it on SEO Press now with these code:

    // OG THUMBNAIL FB 2ND image
    function sp_social_og_thumb($html) {
    if (is_singular( 'product')) {

    global $product;

    $attachment_ids = $product->get_gallery_image_ids();

    if (!empty($attachment_ids)) {
    $html = null;
    foreach( $attachment_ids as $attachment_id ) {
    $html .= '<meta property="og:image" content="'.wp_get_attachment_url($attachment_id).'" />';
    $html .= '<meta name="thumbnail" content="'.wp_get_attachment_url($attachment_id).'" />';
    $html .= "\n";
    }
    }
    }
    return $html;
    }
    add_filter('seopress_social_og_thumb', 'sp_social_og_thumb');

    Is it possible to do it with rankmath?

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for reaching out to us and bringing your concern to our attention.

    At the moment, Rank Math isn’t generating the thumbnail meta tag as we are focused on generating the OG tag instead.

    You may refer to the filter code below to forcibly add it:

    add_action( 'rank_math/head', function() {
      echo '<meta name="..." />';
    }, 99 );

    Hope that helps. Looking forward to helping you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 1 replies (of 1 total)

The ticket ‘Prioritize Product gallery image as the og:image instead of featured image’ is closed to new replies.