Created
September 25, 2015 18:41
-
-
Save pingram3541/b83d672bfd147c971d0a to your computer and use it in GitHub Desktop.
Add Facebook Open Graph Meta Tags
This file contains 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
/* --------------------------------------------------------------------------- | |
* FACEBOOK OPENGRAPH SETTINGS | |
* --------------------------------------------------------------------------- | |
* @wp-filter - language_attributes | |
* @retun - adds og lang tags to doc element | |
* | |
* @wp-hook wp_head | |
* @return - adds og meta tags to pages | |
* --------------------------------------------------------------------------- */ | |
add_filter('language_attributes', 'tda_doctype_opengraph'); | |
function tda_doctype_opengraph($output) { | |
return $output . ' | |
xmlns:og="http://opengraphprotocol.org/schema/" | |
xmlns:fb="http://www.facebook.com/2008/fbml"'; | |
} | |
add_action('wp_head', 'tda_fb_opengraph', 5); | |
function tda_fb_opengraph() { | |
global $post; | |
//$date = date("Y-m-d"); | |
//$time = time(); | |
if(is_single() || is_front_page()) { | |
if(has_post_thumbnail($post->ID)) { | |
$img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'medium'); | |
} else { | |
$img_src = 'http://thedeviantadvantagebook.com/wp-content/uploads/2014/09/sandi-speaks.jpg'; | |
} | |
if($excerpt = $post->post_excerpt) { | |
$excerpt = strip_tags($post->post_excerpt); | |
$excerpt = str_replace("", "'", $excerpt); | |
} else { | |
$excerpt = get_bloginfo('description'); | |
} | |
?> | |
<meta property="og:title" content="<?php echo the_title(); ?>"/> | |
<meta property="og:description" content="<?php echo $excerpt; ?>"/> | |
<meta property="og:type" content="article"/> | |
<meta property="og:url" content="<?php echo the_permalink(); ?>?"/> | |
<meta property="og:site_name" content="<?php echo get_bloginfo(); ?>"/> | |
<meta property="og:image" content="<?php echo $img_src; ?>"/> | |
<?php | |
} else { | |
//return; | |
?> | |
<! -- no fb meta output --> | |
<?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment