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') === '') { ?>
<?php } ?>

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



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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.