Advertisement
abdulawal39

Facebook Share Image Fix for WordPress Theme

Jan 29th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.41 KB | None | 0 0
  1. <?php
  2. function tnc_share_image_fix(){
  3.      if(has_post_thumbnail()){
  4.         $thumb_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 600,315 ), false, '' );
  5.         echo '<meta property="og:image" content="'.$thumb_url[0].'" />';
  6.     } else {
  7.         echo '<meta property="og:image" content="'.get_template_directory_uri().'/images/placeholder.png" />';
  8.     }
  9. }
  10. add_action('wp_head', 'tnc_share_image_fix');
  11. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement