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