Last active
September 24, 2015 19:48
-
-
Save gcoop/800060 to your computer and use it in GitHub Desktop.
Simple script to add obvious Facebook Open Graph attributes to Wordpress posts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function fbOg() | |
{ | |
if (is_single()) | |
{ | |
global $post; | |
$images = preg_split("/\"/", get_the_post_thumbnail( $post->ID, 'thumbnail' )); | |
$first_image = isset($images[5]) ? $images[5] : 'http://example.com/blogLogo.jpg'; // Hardcoded fallback. | |
$attrs = array( | |
"title" => the_title(null, null, false), | |
"url" => get_permalink($post), | |
"site_name" => get_bloginfo('name'), | |
"description"=>get_bloginfo('description'), | |
"image" => $first_image, | |
"type" => "article", | |
"admins" => "505178361,285902231,100000848644298" | |
); | |
foreach ($attrs as $k => $v) | |
{ | |
echo('<meta property="og:'.$k.'" content="'.$v.'" />'."\n"); | |
} | |
} | |
} | |
add_action('wp_head', 'fbOg'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment