Avoiding get_theme_mod Errors

Code Sample Matrix

If you’re getting an error related to get_theme_mod, its most likely from how you’re checking if the returned result is empty. Most developers will probably do the same thing I did: make a variable and assign it to the result of get_theme_mod. Then check if its empty using PHP’s empty() method. Sadly, this is where you’re getting an error. Instead, check if the result is equal to ”, or blank.

/**
* Do this
*/
if ( '' == get_theme_mod( 'something' ) ) { ... }
/**
* Not this
*/
if ( empty( get_theme_mod( 'something' ) ) ) { ... }

Leave a Reply