Skip to content

Instantly share code, notes, and snippets.

@DavidPeralvarez
Created March 29, 2018 14:00
Show Gist options
  • Save DavidPeralvarez/0e40259723c9c4f09ce19745a3fef671 to your computer and use it in GitHub Desktop.
Save DavidPeralvarez/0e40259723c9c4f09ce19745a3fef671 to your computer and use it in GitHub Desktop.
Imagen destacada de WordPress como Facebook Thumbnail
/**
* Facebook Thumb Fixer
*/
add_action('wp_head','fbfixthumbnail');
function fbfixthumbnail(){
global $post;
//If there is a post image
if (has_post_thumbnail()) {
$featuredimg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), "Full");
$result = '
<meta property="og:image" content="'.$featuredimg[0].'" />
<meta itemprop="image" content="'.$featuredimg[0].'" />
';
}else{
$result='
<meta property="og:image" content="https://silicodevalley.com/wp-content/uploads/2016/09/facebook.png" />
<meta itemprop="image" content="https://silicodevalley.com/wp-content/uploads/2016/09/facebook.png" />
';
}
$result .= '
<meta property="og:url" content="'.get_permalink().'" />
<meta property="og:title" content="'.get_the_title($post->ID).'"/>
<meta property="og:description" content="'.get_the_excerpt($post->ID).'"/>
';
echo $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment