How to get a post thumbnailURL of a certain size

How to get a post thumbnailURL of a certain size

Input data:

  • $post_id – ID of the post
  • $size_thumb – e.g. array( 300, 300 ) or a standard / registered name like “middle” etc.
function get_thumbnail_post_url( $post_id, $size_thumb ) {
  $image_id = get_post_thumbnail_id( $post_id );
  $image_array = wp_get_attachment_image_src( $image_id, $size_thumb );
  $image_url = $image_array[0];
  return $image_url;
}

function thumbnail_post_url( $post_id, $size_thumb ) {
  echo get_thumbnail_post_url( $post_id, $size_thumb );
}

Now you can insert in a theme code like this:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:
Inline
Inline