Skip to content

Instantly share code, notes, and snippets.

@hiwelo
Created November 23, 2015 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiwelo/ca8da2ae0be0061bbb3b to your computer and use it in GitHub Desktop.
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
<?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