I'm using: get_theme_mod to show various pieces of info from the theme customizer, in the following format:

<a href=" <?php get_theme_mod( $name, $default ) ?> ">This is the link</a>

I would like to hide the whole line if that particular customizer field is empty.

What could I wrap around the anchor to accomplish this?

$value = get_theme_mod( $name, $default );
if ($value !== $default) { 
   <a href=" <?php echo $value; ?> ">This is the link</a>
  • Awesome, thanks Otto! Funny you answered, as it's from your customizer tutorial I'm following. Where abouts would I place this code? In functions.php? – user2014024 Feb 25 '13 at 23:37
  • Wherever the code you had above is, most likely your template. – Wyck Feb 26 '13 at 3:13

Looking for an answer to displaying default text in place of a customizer set heading. In a funny roundabout way, thepost by @Otto gave me the idea of checking for an empty string.

<?php if( get_theme_mod( 'tcx_portfolio_intro') == '' ) : ?>
<div class="intro">
<h2><?php echo ('nothing here yet'); ?></h2>
<?php endif; ?>

Irrespective of your default value in the customizer setting, you could just compare the theme modification value to an empty string:

$link = get_theme_mod( $name );
if ($link !== '' ) { 
   <a href="<?php echo $link; ?> ">This is the link</a>

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.