unsplash-logo JR Korpa

Avoiding get_theme_mod Errors

Published 2015-04-16

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 these most recent posts:

How to Add a Class to a Metabox

Toggling the visibility of a metabox using a form requires the metabox to have a custom class. This is how to add custom classes to a metabox.

ArtistDataPress Expiration

In case you haven’t heard, ArtistData is shutting down, so the ArtistDataPress plugin will also be shutting down as of October 14.

Building Your First Widget

Watch the video of my presentation about building your first widget from WordCamp Nashville 2013. You can also follow along with the code samples.