Oddly, this one had me scratching my head for an age – obviously not had enough coffee! WordPress customizer doesn’t return results unless saved first – here’s how to return default text if the WordPress customizer field is empty.

Assuming you’ve already set up the setting/control in your customizer file:

 <h2><?php
if ( get_theme_mod( 'tcx_portfolio_intro') == '' ) {
 echo "nothing here yet";
} else {
 echo get_theme_mod( 'tcx_portfolio_intro' ) ;
}
?></h2>

This checks to see if your get_theme_mod has an empty string and if so, replaces it with the ‘nothing here yet’ line. As soon as you enter the text into the field, bingo – it gets replaced by the customizer entry.

Socially enable us...Tweet about this on Twitter0Share on Facebook0Share on Google+0Share on LinkedIn0Share on Reddit0Share on StumbleUpon0Pin on Pinterest0Share on Tumblr

Leave a Reply