Created
February 27, 2016 09:02
-
-
Save danixland/0398978966289faa7e91 to your computer and use it in GitHub Desktop.
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
// opengraph metatags | |
function danixland_opengraph() { | |
global $post; | |
$output = ''; | |
$image = get_template_directory_uri() . '/img/standard-logo.png'; | |
if ( is_home() || is_front_page() ) { | |
$output = '<meta property="og:url" content="' . get_bloginfo('url') . '" />' . "\n"; | |
$output .= '<meta property="og:type" content="website" />' . "\n"; | |
$output .= '<meta property="og:title" content="' . wp_title('•', false, 'right') . '" />' . "\n"; | |
$output .= '<meta property="og:description" content="' . get_bloginfo( 'description' ) . '" />' . "\n"; | |
$output .= '<meta property="og:image" content="' . $image . '" />' . "\n"; | |
} elseif ( is_singular() ) { | |
$output = '<meta property="og:url" content="' . get_the_permalink() . '" />' . "\n"; | |
$output .= '<meta property="og:type" content="article" />' . "\n"; | |
$output .= '<meta property="og:title" content="' . get_the_title() . '" />' . "\n"; | |
$output .= '<meta property="og:description" content="' . get_the_excerpt() . '" />' . "\n"; | |
if ( is_single() && has_post_thumbnail($post->ID) ) { | |
$image = get_the_post_thumbnail_url($post->ID, "medium"); | |
} | |
$output .= '<meta property="og:image" content="' . $image . '" />' . "\n"; | |
} | |
echo $output; | |
} | |
add_action( 'wp_head', 'danixland_opengraph' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment