Created
June 16, 2019 18:16
-
-
Save chrono-meter/ccd509abc41837cc651f7950437cdfd3 to your computer and use it in GitHub Desktop.
WordPress | Thumbnail images in search results
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
<?php | |
/** | |
* Thumbnail images in search results | |
* | |
* @see https://support.google.com/customsearch/answer/1626955 | |
*/ | |
add_action( 'wp_head', function() { | |
if ( is_single() && '' !== ($thumbnail_id = get_post_thumbnail_id()) && false !== ($image = wp_get_attachment_image_src( $thumbnail_id ))) { | |
echo "<meta name=\"thumbnail\" content=\"{$image[0]}\">"; | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment