How to use fallback OpenGraph image, not featured image

#650033
  • Resolved Anonymous
    Rank Math free

    Hello, Rank Math team!

    I noticed that if I set a default OpenGraph image in the Titles/Meta settings, it is overridden by featured images I set on posts. In my mind, those are two different things and I was a bit taken aback by Rank Math treating them as the same.

    What if I want featured images to only be used on the website itself, and I want either the default or individually set OpenGraph image to be displayed when posts are shared on social media?

    I recently built a rather large website where this is the case for all of its pages. They have featured images that provide context on the website’s own front end, but have no relevance for social media sharing.

    For cases like this, is it possible to configure Rank Math so the featured image isn’t used as an OpenGraph image automatically? I’d consider them two different things anyway, and if ever I want to enforce a certain OpenGraph image on a certain post, I can still do that through Rank Math’s social settings on that individual post, no?

    Please let me know if you need any further information.

    Thanks!
    Matt.

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math support.

    You can use the following filter to set a default image as the OpenGraph image for all of your posts and pages:

    add_filter( "rank_math/opengraph/facebook/image", function( $attachment_url ) {
            $attachment_url = 'your image URL';
    	return $attachment_url;
    });
    
    add_filter( "rank_math/opengraph/twitter/image", function( $attachment_url ) {
            $attachment_url = 'your image URL';
    	return $attachment_url;
    });

    Here is how to add a filter to your site: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Please note that the filter will also override the image you set in the Social tab. You will have to modify it and exclude the post ID if you ever want to change the OG image of a post.

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    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 ‘How to use fallback OpenGraph image, not featured image’ is closed to new replies.