Advertisement
borkolivic

Untitled

Feb 24th, 2015
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. //Adding the Open Graph in the Language Attributes
  2. function add_opengraph_doctype( $output ) {
  3.         return $output . ' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"';
  4.     }
  5. add_filter('language_attributes', 'add_opengraph_doctype');
  6.  
  7. //Lets add Open Graph Meta Info
  8.  
  9. function insert_fb_in_head() {
  10.     global $post;
  11.     if ( !is_singular()) //if it is not a post or a page
  12.         return;
  13.         echo '<meta property="fb:admins" content="YOUR USER ID"/>';
  14.         echo '<meta property="og:title" content="' . get_the_title() . '"/>';
  15.         echo '<meta property="og:type" content="article"/>';
  16.         echo '<meta property="og:url" content="' . get_permalink() . '"/>';
  17.         echo '<meta property="og:site_name" content="YOUR SITE NAME GOES HERE"/>';
  18.     if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
  19.         $default_image="http://example.com/image.jpg"; //replace this with a default image on your server or an image in your media library
  20.         echo '<meta property="og:image" content="' . $default_image . '"/>';
  21.     }
  22.     else{
  23.         $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
  24.         echo '<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>';
  25.     }
  26.     echo "
  27. ";
  28. }
  29. add_action( 'wp_head', 'insert_fb_in_head', 5 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement