In a plugin I'm working on there is a line:
echo the_post_thumbnail(array(155,55));
It throws a inspection warning:
'void' function 'the_post_thumbnail' result used
Is there a best practice method of dealing with this or is the PhpStorm inspection overly aggressive?
In a plugin I'm working on there is a line:
echo the_post_thumbnail(array(155,55));
It throws a inspection warning:
'void' function 'the_post_thumbnail' result used
Is there a best practice method of dealing with this or is the PhpStorm inspection overly aggressive?
Share Improve this question asked Apr 23, 2020 at 15:54 davemackeydavemackey 3152 silver badges18 bronze badges1 Answer
Reset to default 3The solution is simple, don't echo
the result of that function, there is no result to echo.
echo the_post_thumbnail(array(155,55));
Is equivalent to something like this:
echo '';
the_post_thumbnail(array(155,55));
Functions that begin with the_
in WP don't return things, they output things. Some of them let you pass a parameter that lets them return instead, but those are the exception, also don't do that.
The echo
is both unnecessary, and incorrect PHP.
So, just use this:
the_post_thumbnail([ 155, 55 ]);
Notice I also swapped the old style array syntax for modern array syntax, and spaced out the parameters.