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:

Read More
<?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

Related posts

2 comments

  1. 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>';
        }
    
    ?>
    
  2. 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

Comments are closed.