2

I'm trying to develop a theme. but "Display Site Title and Tagline" checkbox not working nothing change when i check or uncheck the site tile and tagline still exist. also the color option not giving any effect? please help my code for the header text is:

<header class="image-bg-fluid-height" id="startchange" style="background-image: url('<?php echo( get_header_image() ); ?>')" >

      <h1 class="h1-hdr"><?php bloginfo('name');?> </h1>
        <br/> <br/>
        <P id="header-pa"><?php bloginfo('description');?> </P>
        <a  class="btn btn-primary btn-lg outline " role="button" href="#" id="btn-header">WATCH A VIDEO</a>
        <br/> <br/> 
    </header>
1

3 Answers 3

3

this peace of code will help you

        <?php
            if (display_header_text()==true){
                echo '<h1>'.get_bloginfo( 'name' ) .'</h1>';
                echo '<h2>'.get_bloginfo('description').'</h2>';                            
            } else{
                  //do something
            }
          ?>
1
  • This did the trick for me. Cheers bro! +1
    – AndrewL64
    Commented Apr 19, 2018 at 10:22
1

Above answers didn't work for me - this did. This displays the site description if the box is checked and there's text in the description field.

if ( (get_theme_mod('header_text') != 0) && (get_bloginfo('description') != '') ) {
  echo '<div class="site-description">' . get_bloginfo('description') . '</div>';
}

This is also useful if you're trying to customize the display based on the Customizer's settings:

var_dump(get_theme_mods());
2
  • Great snippet but change !== 0 to be != 0 instead. Commented Oct 27, 2022 at 23:33
  • Good point @JesseNickles, done!
    – Michelle
    Commented Nov 8, 2022 at 19:26
0

The answer above didn't work for me. After examining the twenty seventeen theme I came up with this solution that worked for me. Add this to your wordpress theme page as appropriate.

<?php
        $site_description = get_bloginfo( 'description', 'display' );

        if ( $site_description || is_customize_preview() ) :
        ?>
          <h2 class="site-description"><?php echo $site_description; ?></h2>
        <?php endif; ?>

The CSS Class "site-description" can be defined by adding the following to your functions.php. Most sites have this set up already so if you are modifying a theme made by someone else it's worth looking for this to check the H2 Css Class name.

add_theme_support('custom-logo');

function yourPrefix_custom_logo_setup()
{
    $defaults = array(
        'height' => 207,
        'width' => 276,
        'flex-height' => false,
        'flex-width' => false,
        'header-text' => array('site-title', 'yourPrefix-site-description'),
    );
    add_theme_support('custom-logo', $defaults);
}
add_action('after_setup_theme', 'yourPrefix_custom_logo_setup');

You should change yourPrefix to whatever the prefix is for the theme that you are working on in order to prevent conflicts etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.