How to hide get_theme_mod if field empty

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

<a href="https://wordpress.stackexchange.com/questions/88378/<?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?

3 s
3

$value = get_theme_mod( $name, $default );
if ($value !== $default) { 
?>
   <a href="https://wordpress.stackexchange.com/questions/88378/<?php echo $value; ?>">This is the link</a>
<?php 
}

Leave a Comment