OG:Image from Custom Field – Filter

#24622
  • Resolved Atakan
    Rank Math free

    Hello there,

    I’ve a directory website which contains more than 1000 resources in it. All of the resources have a featured image and those featured images are inserted as string on a custom field. All the images are also on my S3 bucket. They are taken from there and used on a custom template on one of our page templates.

    My question is, is there any filter for og:image property to get images from the custom fields rather than WordPress Featured Image. It’s not quite possible to import our S3 Bucket to our WordPress Library. Though I don’t want to do that too. But still I want to point featured images for a better social media presence. At the moment, they are all same — possibly taken the default image.

    Let me know how can I do that.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Atakan
    Rank Math free

    I’ve found the solution by following your API filters… I’m sharing the code so hopefully someone will find it when it’s needed.

    add_filter( "rank_math/opengraph/facebook/image", function( $attachment_url ) {
    	if(is_singular()){
    		global $post;
    	  $post_slug = $post->post_name;
    		$attachment_url = 'cdn_url' . $post->post_name . '.jpg';
    	}
    	return $attachment_url;
    });
    add_filter( "rank_math/opengraph/twitter/image", function( $attachment_url ) {
    	if(is_singular()){
    		global $post;
    	  $post_slug = $post->post_name;
    		$attachment_url = 'cdn_url' . $post->post_name . '.jpg';
    	}
    	return $attachment_url;
    });
    Todd
    Rank Math free

    Hi Atakan,

    Thanks for getting in touch with and we are sorry for the late reply due to the holiday season.

    I am glad that you found the filter.

    If you need help with anything else, please open a new support ticket here so we can help.

    We are always here for assistance.

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

The ticket ‘OG:Image from Custom Field – Filter’ is closed to new replies.