How to get all featured image sizes and their URLs?

Is there a standard way to get all the registered sizes of the featured images?
One can register different sizes with add_image_size().
What I need, is to get all the sizes of a featured image of a post.
Something like this:

$sizes = get_post_feature_image_sizes($postid);

…which will return an array of objects like this (here in JSON format):

[
{width: 200, height: 300, url: 'http://.........../wp-content/uploads/2015/10/file-200x300.jpg'},
{width: 300, height: 400, url: 'http://.........../wp-content/uploads/2015/10/file.jpg'},
]

Is there anything like this, or I will have to scan all the upload folder file names with regex?

3

I don’t remember a function that will do precisely that, but it is easily achieved with API overall:

  1. Retrieve attachment ID with get_post_thumbnail_id()
  2. Retrieve available sizes with get_intermediate_image_sizes()
  3. For each size use wp_get_attachment_image_src(), which gives precisely data you need (URL and dimensions).

Leave a Comment