I am trying to get both full
and thumbnail
images from post with wp_get_attachment_image_url
:
wp_get_attachment_image_url( get_the_ID(), array('thumbnail, full'));
I know that by default size
is thumbnail
and I read from documentation that I can pass and array of sizes, but with above example, I am getting an error:
A non-numeric value encountered
The documentation is not clear about how to pass an array of sizes as parameter.
I am trying to get both full
and thumbnail
images from post with wp_get_attachment_image_url
:
wp_get_attachment_image_url( get_the_ID(), array('thumbnail, full'));
I know that by default size
is thumbnail
and I read from documentation that I can pass and array of sizes, but with above example, I am getting an error:
A non-numeric value encountered
The documentation is not clear about how to pass an array of sizes as parameter.
Share Improve this question asked Jan 13, 2019 at 23:16 gdfgdfggdfgdfg 1721 silver badge15 bronze badges1 Answer
Reset to default 1You’re almost correct.
You really can pass an array as size parameter for that function, but...
$size (string|array) (Optional) Image size to retrieve. Accepts any valid image size, or an array of width and height values in pixels (in that order). Default value: 'thumbnail'
So you can’t use it in the way you wanted to...
You have to pass name of the size or an array that will define the size in pixels (width and height).
You can get only one size with one call of that function (as it returns only one value - url of image in given size).
But that’s not a problem, just call it twice:
$thumb_url = wp_get_attachment_image_url( get_the_ID(), 'thumbnail');
$full_url = wp_get_attachment_image_url( get_the_ID(), 'full');