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

php - Issues when changing == to ===

programmeradmin2浏览0评论

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', '' ) ) {}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论