admin管理员组文章数量:1023273
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 01 Answer
Reset to default 3The 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', '' ) ) {}
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 01 Answer
Reset to default 3The 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', '' ) ) {}
本文标签: phpIssues when changingto
版权声明:本文标题:php - Issues when changing == to === 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745565303a2156412.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论