I’m having a Like button on my WordPress site. I’d like to use the og:image meta-tag from facebook to display the proper image when somebody likes it.
I need to add that tag in the head of the page.
So far I have this in single.php:
function fb_image_meta($image) {
return '<meta property="og:image" content="$image" />';
}
add_action('wp_head', 'fb_image_meta', 10, $image_thumbnail);
When I look at the source of an article, The meta tag doesn’t show up.
What am I doing wrong?
Use this code in functions.php
You should take care of
$image_thumbnail
– it must be declared before wp_head. If this is a post thumbnail, you can get it with this code (before the add_action call):Based off of Nikolay’s answer:
Find and replace your wp_head() call (probably in header.php) with this: