Created
November 23, 2015 22:32
-
-
Save hiwelo/ca8da2ae0be0061bbb3b to your computer and use it in GitHub Desktop.
La fonction getThumbnail permet la récupération rapide de l'URI de l'image à la une d'un article WordPress
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 | |
/** | |
* Return the thumbnail URI of an asked element | |
* @param int $post_id Article's ID, if necessary | |
* @param string $size Size of the thumbnail | |
* @return string Cover image URI | |
*/ | |
function hwlo_getThumbnail($post_id = null, $size = 'thumbnail') { | |
if (!is_numeric($post_id) && is_string($post_id)) { | |
$size = $post_id; | |
$post_id = null; | |
} | |
$thumb_id = get_post_thumbnail_id($post_id); | |
$thumb_url = wp_get_attachment_image_src($thumb_id, $size); | |
return $thumb_url[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment