Support » Fixing WordPress » Featured image is not displayed when sharing to Facebook

  • I don’t know whether this problem is due to WordPress, Facebook, or the theme I am using (Enfold), but with some posts, when I try to share them to Facebook, I can’t get the featured image to show. On some posts the featured image is displayed; on others a generic, completely irrelevant image is displayed, and on other posts no image shows at all.

    I’ve installed a new sharing buttons plugin, as I was wondering if the theme’s in-built sharing buttons were to blame. But I’m getting exactly the same problem with the theme’s sharing buttons and with the plugin ones.

    Does anyone know why this might be happening and how I can fix it so that the featured image is always displayed when sharing posts to Facebook?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Look at your site’s front end code. Is there something like this in the <head> section?

    <meta property="og:image" content="https://mywebsite.com/wp-content/uploads/2016/06/my-image.jpg" />

    If not, Facebook is just trying to grab whatever image it can. You need to set the Featured Image via Open Graph to tell FB explicitly what to use. You can try this in functions.php, works for me (though as part of a much larger chunk of code I use to set all OG, Twitter cards and more):

    function clicknathan_og_image_url() {
    	global $post;
    	if (is_singular()) {
    		if (has_post_thumbnail()) {
    			$og_image_url = the_post_thumbnail_url( 'large' );
    			// if that doesn't work, try
    			// $og_image_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    		}
    	}
    	return $og_image_url;
    }
    
    add_action('wp_head','clicknathan_seo');
    function clicknathan_seo() {
    	global $post;
    	
    	if (is_singular()) {
    		echo '<meta property="og:image" content="'.clicknathan_og_image_url().'" />';
    	}
    }

    Probably could just combine those two functions into one, too. Again, just grabbing this from code I wrote previously that works, but I did cut a lot out of it for the sake of only applying it to your solution.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Featured image is not displayed when sharing to Facebook’ is closed to new replies.