Force open graph image as featured image?

#390345
  • Resolved Brian Tetrault
    Rank Math free

    We have a situation where we’re using a custom plugin connected to an outside API to pull in and generate a post (custom post type) automatically. This includes adding a featured image.

    Is there a way to force the open graph image to be the featured image? Currently, when I share a link to Facebook, for example, it’s seemingly still finding the first image in the page source—in this case an image we have in a custom dropdown mega menu.

    Because these posts are all automatic with no manual intervention, I’m trying to avoid having to go into each post individually to set the social image in the Rank Math meta box.

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

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.

    I’ve checked the featured image you have set for that page, and it seems that its resolution is too big (1024×1024).

    Please ensure that the image file format you are uploading is only between jpeg, gif, or png, and the image resolution is as close as 1200 x 630 pixels as per Opengraph Standards:
    https://rankmath.com/kb/open-graph-image-not-displaying/#num-4-2-image-dimensions-image-format

    Once done, clear your website’s cache and check again using Facebook Debugger Tool.

    I hope that helps.

    Thank you.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Where do you see that the featured image is that large? Because it’s coming in from the API, I don’t quite see how it would be formatted as such.

    Is there a way to block certain images from the open graph across the entire site? The 3 images in the mega menu would be the first 3 I’d block, but I’m not sure how to go about that.

    Hello,

    Can you please try using the filter given below and see if that resolves the issue:

    add_filter( "rank_math/opengraph/facebook/image", function( $attachment_url ) {
    	global $post;
    	
    	if (get_the_post_thumbnail_url($post->ID)) {
    		$attachment_url = get_the_post_thumbnail_url($post->ID);
    	}
    	
    	return $attachment_url;
    });
    
    add_filter( "rank_math/opengraph/twitter/image", function( $attachment_url ) {
    	global $post;
    	
    	if (get_the_post_thumbnail_url($post->ID)) {
    		$attachment_url = get_the_post_thumbnail_url($post->ID);
    	}
    	
    	return $attachment_url;
    });

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

    Hope this helps. Let us know if you need any other assistance.

    Damn. That filter looked really promising. I applied the filter in the Code Snippets plugin, no caching, no CDN, sharing to FB still just pulling the menu image still. Any other thoughts?

    Hello,

    We might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress login in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look 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 6 replies - 1 through 6 (of 6 total)

The ticket ‘Force open graph image as featured image?’ is closed to new replies.