Would anyone be able to point me in the right direction for writing a conditional statement in my header.php file using the function, whereby if the custom logo is uploaded using the WordPress customizer, the

element that usually contains the site title is replaced by the custom logo, so that it doesn’t display both the site title and the logo at the same time?

I am building a custom theme using the Underscores starter theme on WordPress version 4.7.4

Here is the current code in my header.php file, with the logo currently called independently above the .site-title using the function.

<header id="masthead" class="site-header" role="banner">
    <div class="container">
        <div class="site-branding">

            <?php the_custom_logo(); ?>

            <?php
            if ( is_front_page() && is_home() ) : ?>
                <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
            <?php else : ?>
                <p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p>
            <?php
            endif;

            $description = get_bloginfo( 'description', 'display' );
            if ( $description || is_customize_preview() ) : ?>
                <p class="site-description"><?php echo $description; /* WPCS: xss ok. */ ?></p>
            <?php
            endif; ?>

        </div><!-- .site-branding -->

        <nav id="site-navigation" class="main-navigation" role="navigation">
            <button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"><?php esc_html_e( 'Primary Menu', 'odtcreative' ); ?></button>
            <?php wp_nav_menu( array( 'theme_location' => 'menu-1', 'menu_id' => 'primary-menu' ) ); ?>
        </nav><!-- #site-navigation -->
    </div>
</header><!-- #masthead -->

Read more here: Replace site title <h1> with logo when logo is uploaded in customizer using <?php the_custom_logo(); ?>


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: