Reputation: 1155
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?
Upvotes: 1
Views: 1746
Reputation: 624
Based off of Nikolay's answer:
function fb_image_meta($image) {
echo '<meta property="og:image" content="$image" />';
}
add_action('wp_head', 'fb_image_meta', 10, 1);
Find and replace your wp_head() call (probably in header.php) with this:
do_action('wp_head', $fbImage);
Upvotes: 0
Reputation: 1404
Use this code in functions.php
function fb_image_meta($image) {
echo '<meta property="og:image" content="$image" />';
}
add_action('wp_head', 'fb_image_meta', 10, $image_thumbnail);
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):
global $post;
$image_thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large');
Upvotes: 2