Hello,
We apologize for the issue you are facing with setting Open Graph images for your posts. To use a custom meta key like "thumbnail" as your Open Graph image in Rank Math, you can utilize a filter to override the default behavior.
You can add the following code snippet to your theme’s functions.php
file or a custom plugin:
add_filter('rank_math/opengraph/pre_set_content_image', function() {
$thumbnail_url = get_post_meta(get_the_ID(), 'thumbnail', true);
return !empty($thumbnail_url) ? $thumbnail_url : false;
});
This code retrieves the URL from your custom meta key and sets it as the Open Graph image if it exists. If there is no URL, it will fall back to the default behavior.
Make sure to test this after implementing the code to ensure that the correct image is being used when sharing your posts on social media.
If you need further assistance or a more comprehensive setup, we recommend our professional setup service, which ensures that your Rank Math plugin is configured correctly according to the latest SEO standards. You can find more information about this service at Rank Math Services.
Thank you for raising this concern! If you have any more questions or need additional help, feel free to reply to this ticket.
Sources:
Open Graph Meta Tags » Rank Math
Open Graph/Social Preview Image Is Not Displayed » Rank Math
Open Graph/Social Preview Image Is Not Displayed » Rank Math
Hello,
Thank you for reaching out to us.
It seems that you’re currently using the Rank Math PRO plugin, but the account you used to open this ticket is a free account.
Can you please search and forward a receipt from FastSpring.com so we can locate your account and verify it?
The og:image uses primarily the image you set in the social tab within the Rank Math meta box while editing the page(OpenGraph image). If you set none, it then tries to use the featured image. If this is not available it uses the first image in the post. Where the post/page doesn’t have any image it then uses the default OpenGraph image set at WordPress dashboard > Rank Math > Titles & Meta > Global Meta > Opengraph Thumbnail.
If you want to however, force the use of the default/fallback opengraph image as og:image everywhere, you may need to use this filter:
add_filter('rank_math/opengraph/pre_set_content_image', function() { return true; });
And here’s a guide on how you can add the filter to your site:
https://rankmath.com/kb/filters-hooks-api-developer/
We hope this helps. Please let us know if you have further questions or concerns.
Thank you.
Thank you for your help, it worked successfully. Now I can see the correct OG Image URLs
Hello,
We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.
If you don’t mind me 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 do 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.