php - Issues when changing == to ===

What am I missing... when using === in the code, the front end doesn't show an element at all until I disable and t

What am I missing... when using === in the code, the front end doesn't show an element at all until I disable and then re-enable an option in the WP Customizer.

For example, I have a logo that can be disabled. After installing the theme and viewing the site through the Customizer, the logo shows fine. But when viewing it on the front end, the logo isn't shown at all until I disable the logo and then re-enable again in the Customizer.

Here's the code:

<?php if( get_theme_mod('hide_logo') === '') { ?>
LOGO CODE
<?php } ?>

== works fine, though I'm making a little theme for sale, and the marketplace requires strict equality checks.

Thanks.

What am I missing... when using === in the code, the front end doesn't show an element at all until I disable and then re-enable an option in the WP Customizer.

For example, I have a logo that can be disabled. After installing the theme and viewing the site through the Customizer, the logo shows fine. But when viewing it on the front end, the logo isn't shown at all until I disable the logo and then re-enable again in the Customizer.

Here's the code:

<?php if( get_theme_mod('hide_logo') === '') { ?>
LOGO CODE
<?php } ?>

== works fine, though I'm making a little theme for sale, and the marketplace requires strict equality checks.

Thanks.

Share Improve this question asked Apr 22, 2019 at 20:20 RayRay 251 silver badge6 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 3

The get_theme_mod() function could return an explicit false. The === operator looks for exact matches, so in the case of hide_logo not being set the function would return false and false is not an exact match to an empty string ''. The == operator is a bit more forgiving in that sense which is why you don't have an issue there.

You could supply a default value as the second parameter which will be returned if a value is not set or does not exist:

if( '' === get_theme_mod( 'hide_logo', '' ) ) {}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745565304a4633357.html

相关推荐

  • php - Issues when changing == to ===

    What am I missing... when using === in the code, the front end doesn't show an element at all until I disable and t

    17小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信