最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Is there a best practice remediation for PhpStorm's warning that void function the_post_thumbnail is used?

programmeradmin4浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 3

The 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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论