Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get_the_post_thumbnail_url() not working when adding an image size

Tags:

wordpress

I have a weird situation when I am trying to use get_the_post_thumbnail_url() in Wordpress.

To be more precise, I have this variable:

$postImage = get_the_post_thumbnail_url('article-thumbnail-image');

and it returns a blank value. If I use:

$postImage = get_the_post_thumbnail_url();

the value returned is correct but it has a different image size (150x150). Now the weird part is if I use:

the_post_thumbnail_url('article-thumbnail-image');

it shows the right value as this image size is registered in functions.php but I need to use the GET function.

Am I doing something wrong?

like image 201
Ganikkost Avatar asked Feb 12 '17 14:02

Ganikkost


1 Answers

There are two arguments in get_the_post_thumbnail_url(). You'll need to either use null or the post_id/post for the first argument and the size would be the second. https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/

like image 57
user3080408 Avatar answered Sep 28 '22 19:09

user3080408