0

I want to update my <meta property="og:image" content="http://amemoirproject.com/facebook/og-image.png"/> tag in the head with the current post's feature image. How can I do that?

1

On a single post page the $post variable should work for you. It is set well before the page header prints. You will need get_post_thumbnail_id and wp_get_attachment_image_src

 if (is_single()) {
    $thumbid = get_post_thumbnail_id($post->ID);
    $imgsrc = wp_get_attachment_image_src($thumbid);
    $src = $imgsrc[0];
    //   wp_die(var_dump($src)); // debugging/confirmation
}

I don't know how your theme is written or how that meta tag is inserted so I can't say exactly how to insert the image source into that tag, but the above will get you the URL.

$src will be NULL if there is no featured image so use isset or empty to check the variable before using it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.