admin管理员组文章数量:1384836
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.
本文标签:
版权声明:本文标题:plugins - Is there a best practice remediation for PhpStorm's warning that void function the_post_thumbnail is used? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744538934a2611487.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论