How to set ACF image as default thumbnail for Facebook sharing.

#506678
  • Resolved Cody Clifton
    Rank Math free

    Looking for hook or filter to map an ACF image in a CPT to the Thumbnail Facebook uses when sharing the post.

    I have thousands of Obituaries in a custom post type. Within these CPTs I have an ACF Field, “profile_picture”. I would like to make this image the default image Facebook uses when sharing to Facebook. I realize I can change it manually in the Snippet Preview Editor but the client would like to pull the “profile_picture” as the default automatically.

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

    Thank you for contacting Rank Math support and bringing your concern to our attention.

    Assuming the custom field profile_picture will return an absolute image path, you may refer to this filter code below:

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

    Let us know how that goes. Looking forward to helping you.

    Worked perfectly. Thank you!

    Hello,

    We are super happy that this issue is already resolved. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind us 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 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.

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

The ticket ‘How to set ACF image as default thumbnail for Facebook sharing.’ is closed to new replies.