function themify_open_graph(){
$og = "\n".'<!-- Open Graph Tags -->'."\n";
$og .= '<meta property="og:site_name" content="' . get_bloginfo('name') . '" />' . "\n";
if ( is_home() || is_front_page() ){
$type = 'website';
$description = get_bloginfo('description');
$url = home_url();
} else {
$type = 'article';
$url = apply_filters( 'the_permalink', get_permalink() );
if( is_category() || is_tag() || is_tax() ){
$description = strip_tags(category_description());
} elseif( is_search() ){
$description = get_search_query();
} else {
$description = strip_tags( get_the_excerpt() );
if( !$description ){
global $post;
$description = strip_tags($post->post_content);
$excerpt_length = 29;
$words = explode(' ', $description, $excerpt_length + 1);
if(count($words) > $excerpt_length){
array_pop($words);
$words[] = '';
$description = implode(' ', $words);
}
}
}
}
$og .= '<meta property="og:type" content="' . apply_filters('themify_og_type', $type) . '" />' . "\n";
$og .= '<meta property="og:description" content="' . apply_filters('themify_og_description', esc_attr($description)) . '" />' . "\n";
$og .= '<meta property="og:url" content="'. esc_url($url) . '" />' . "\n";
if( is_singular() ){
if ( has_post_thumbnail() ){
$imagesrc = wp_get_attachment_image_src( get_post_thumbnail_id(), 'medium' );
$thumb = $imagesrc[0];
} else {
global $post;
$thumb = get_post_meta($post->ID, 'post_image', true);
}
if( $thumb ){
$og .= '<meta property="og:image" content="' . apply_filters('themify_og_image', $thumb) . '" />' . "\n";
}
$og .= '<meta property="og:title" content="' . the_title_attribute( array( 'echo' => false ) ) . '" />' . "\n";
}
$og .= '<!-- End Open Graph Tags -->';
echo apply_filters('themify_open_graph', $og);
}
add_action('wp_head', 'themify_open_graph');