Skip to content

Instantly share code, notes, and snippets.

@amorkovin
Last active November 28, 2018 19:53
Show Gist options
  • Save amorkovin/b1ebe37db3812efc079ea4c384143271 to your computer and use it in GitHub Desktop.
Save amorkovin/b1ebe37db3812efc079ea4c384143271 to your computer and use it in GitHub Desktop.
Open Graph для WordPress
<?php
add_action( 'wp_head', 'morkovin_opengraph_add_head' );
function morkovin_opengraph_add_head(){
if(function_exists('show_morkovniy_opengraph')) { show_morkovniy_opengraph(); }
}
function show_morkovniy_opengraph() {
if ( is_single() ) {
$title = get_the_title();
$post = get_post( get_the_ID() );
$content = $post->post_content;
$description = wp_trim_words($content, 50, '...');
$img = '';
$w = 1000; $h = 480;
if ( kama_thumb_src() ) {
$img = kama_thumb_src('w='.$w.'&h='.$h);
} else {
$img = kama_thumb_src('w='.$w.'&h='.$h.'&src='.get_stylesheet_directory_uri().'/images/no-photo.jpg');
}
echo '<meta property="og:title" content="'.$title.'" />';
echo "\n";
echo '<meta property="og:description" content="'.$description.'" />';
echo "\n";
echo '<meta property="og:image" content="'.$img.'" />';
echo "\n";
echo '<meta property="og:image:width" content="'.$w.'" />';
echo "\n";
echo '<meta property="og:image:height" content="'.$h.'" />';
echo "\n\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment