Support

Account

Home Forums General Issues Image Field array/variable issue in regards to Facebook/Social Open Graph Data

Solving

Image Field array/variable issue in regards to Facebook/Social Open Graph Data

  • Hello,

    I am having a bit of a problem with my Facebook sharing, and I was hoping for some input.

    I am generating og data for Facebook using variables in a custom template. I am using all the og data meta fields, and all of them are being recognized in my source code. I go to the Facebook debugger, and it is grabbing every single og meta field except for the og:image field. The og:image is being left blank (content=””), even though the image is in my source code.

    I am using Advanced Custom Fields to generate a field called “Book Cover” for a website that allows writers to sign up to share their work. I created a book information section in WP using Custom Fields. The Book Cover Field is being used to populate the Facebook Sharing, so when a book is shared, the book cover is attached as the thumbnail.

    It if baffling that the image url shows in my source code, but Facebook isn’t recognizing it right away. So, basically, as soon as I upload a book, I go to the page and view the source code, and I get all of the og data filled in, then I go to share the page, and the thumbnail does not get included even though it is in the source code, then I go to the Facebook debugger tool and the debugger pulls the og mate data from my source code, but the og:image is shown as blank even though it is not blank in the source code.

    My code to build the og meta data out is:

    function mar_set_fb_og() {
    
    	$image = get_field('book_cover', get_the_id() );
    	$book_cover_share = $image['sizes']['thumbnail'];
    	echo '<meta property="og:image" content=" ' . $book_cover_share . '" /> ' . "\n";
    	
    	echo '<meta property="og:url" content="' . get_the_permalink() . '" />' . "\n";
    	echo '<meta property="og:description" content="' . get_the_excerpt() . '"/>';
    	echo '<meta property="og:title" content="' . get_the_title() . '" />' . "\n";
    	echo '<meta property="og:image:type" content="image/jpeg" />' . "\n";
    	echo '<meta property="og:image:width" content="150" />' . "\n";
    	echo '<meta property="og:image:height" content="150" />' . "\n";
    }
    add_action( 'genesis_meta', 'mar_set_fb_og' );

    I feel like it is because my og:image is coming from an Advanced Custom Fields variable. I tried using static content instead of the ACF variable, and the image shows up in the debugger tool. So, it is somehow related to the ACF variable. The WP variables, such as the title, and description, etc work immediately, just not the ACF variable… strange… I have also tried making a static string variable, and that works, too.

    Using the debug tool, I “Fetch new scrape information”, which replaces the cached version of the page with the new version, and after hitting the button a few times, the image finally shows up, but it should show upo immediately, and it isn’t.

    Obviously, since this is a member driven site, I don’t want to have to manually refresh every single book that is added, so that the share works properly.

    Any input would be appreciated.

    Cheers!

  • I’m having a similar problem, would anyone care to share a working solution with us? Surely, this has been resolved within the last four years.

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

The topic ‘Image Field array/variable issue in regards to Facebook/Social Open Graph Data’ is closed to new replies.