• Resolved Spencer Hill

    (@s3w47m88)


    I successfully enabled the Facebook / OpenGraph meta tags. And they successfully display the sites data.

    However, when on a Custom Post Type called Listings, and I click Facebook share, it displays the fallback image instead of the listing image. Although, all other information – such as the title, description, etc… are correct to the listing.

    I cannot find any documentation on how to inform The SEO Framework about how to override this and use the actual Listing featured image.

    Can someone share some citations or insight? Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hi Spencer,

    Facebook tends to keep a very sturdy cache of your pages. This means that updating your pages won’t result in changes at Facebook.

    We wrote a blog post about this, there you can learn how to refresh Facebook’s cache.

    Thread Starter Spencer Hill

    (@s3w47m88)

    Hi Sybre,

    Thanks for the reply and being swift. However, I think you may have misunderstood what I’m trying to accomplish.

    I’m not having an issue with the image caching, it’s flat out not using the pages featured image. You can see this in the URL in the site code even before it gets to Facebook.

    I’m specifically wondering if there is a Hook of some kind that allows me to tell The SEO Framework to use a specific image URL instead of the fallback.

    Thanks for your time.

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi Spencer,

    The “Listing Image” may not be one of the images The SEO Framework knows about. TSF uses the “Featured Image” field (stored as _thumbnail_id post meta), but the CPT might’ve registered it differently.

    I recommend using the image upload field supplied with every post. Alternatively, altering the CPT to use the well-known _thumbnail_id field may be a good idea, but unwanted side-effects may occur.

    Nevertheless, there is a hook available, you’ll have to fill in the image index if your logic finds one. Here’s a freehand, untested example:

    add_filter( 'the_seo_framework_og_image_args', function( $args ) {
    
    	$tsf = the_seo_framework();
    
    	//? Admin-compatible query checks.
    	if ( $tsf->is_singular() ) {
    		$post_type = get_post_type() ?: $tsf->get_admin_post_type();
    
    		if ( 'my_post_type' === $post_type ) { // change this
    			$meta_id = get_post_meta( $tsf->get_the_real_ID(), 'listing-image-key', true ); // change the key
    
    			if ( $meta_id && wp_attachment_is_image( $meta_id ) ) {
    				$args['image'] = wp_get_attachment_image_src( $meta_id, 'full', false );
    			}
    		}
    	}
    
    	return $args;
    } );

    I hope this helps! Cheers ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How do you pass an image to the Facebook meta tag?’ is closed to new replies.