I want to add the featured image URL of a post to the header. When a Facebook user shares a Wordpress page, this code in the header:
The rel="image_src"
attribute is what facebook is searching for.
<link rel="image_src" href="FEATUREDIMAGEURL">
Will return a specific image for the share. However, I cannot figure out how to add the URL of the post's featured image... Can you?
I tried this:
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ); ?>
<link rel="image_src" href="<?php echo $image; ?>">
<?php endif; ?>
But it gave me a Parse error: syntax error, unexpected ';'
error.
get_post_thumbnail_id();
. So it's exactly what error message tells you. Hint: There's a line number and filename hidden in the error message.