Skip to main content

<Slushman />

unsplash-logo JR Korpa

Avoiding get_theme_mod Errors

Published Apr 16, 2015

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

Gist of the code above

Share this post!

Check out the most recent posts:

How to Center in CSS

This is the ultimate guide to centering elements like images, text, and just about anything else using CSS.