Mikey Musch
Mikey Musch

Reputation: 609

Display Tagline if Tagline Exists - Wordpress

I'd like to echo out a few lines of HTML as well as my tagline if the tagline exists. I'm not sure how to check if a tagline exists.

Here is where I'm up to:

<?php if (bloginfo('description')) 
    echo '<div class="tagline-message"><div><h3>
          <?php bloginfo("description"); ?>
          </div></div></h3>'
?>

This doesn't work as saying bloginfo('description') in the if condition is not the correct usage of bloginfo()

How do I check if a tagline exists?

Thanks!
- Mikey

Upvotes: 2

Views: 1179

Answers (2)

rnevius
rnevius

Reputation: 27092

You should be using get_bloginfo() (you need to return the value to the conditional, rather than print/echo it):

<?php 
    $description = get_bloginfo('description');

    if ( $description ) {
        echo '<div class="tagline-message"><div><h3>' . $description . '</div></div></h3>';
    }

?>

Upvotes: 2

Steve
Steve

Reputation: 9571

Use the get_option method to determine if a setting exists. It will return false if no value exists for the setting. Note that blogdescription is the setting name for Tag Line.

<? php if (get_option('blogdescription')) 
    echo '<div class="tagline-message"><div><h3>
          <?php bloginfo('description'); ?>
          </div></div></h3>'
?>

Reference: https://codex.wordpress.org/Function_Reference/get_option

Upvotes: -1

Related Questions