Last active
June 6, 2021 16:19
-
-
Save Jany-M/2abdb626cf094a36b578eaeeaa48787e to your computer and use it in GitHub Desktop.
[WP] Get an image for Open Graph
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 | |
// Get an image for Open Graph - Uses WP Imager https://github.com/Jany-M/WP-Imager | |
if(is_singular()) { | |
global $post; | |
if(function_exists('wp_imager')) { | |
$img = wp_imager(1200, 630, 1, '', '', '', true ); | |
} elseif(has_post_thumbnail($post->ID)) { | |
$img = get_the_post_thumbnail_url( $post->ID, array(1200,630)); | |
} | |
} else { | |
$img = get_stylesheet_directory_uri().'/img/placeholder.jpg'; | |
} | |
?> | |
<meta property="og:image" content="<?php echo $img; ?>" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment