Want to add a logo to theme customizer

I have added a logo upload in a child theme of twentythirteen. It works great but the only issue i’m having is getting the site title to be replaced by the logo. I have tried several if/else statements and none seem to work.

Is it possible to just change the H1 to show the Site Title unless a logo has been uploaded?

Here is the code.

<a>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
<h1 </a><a><img src='<?php echo esc_url( get_theme_mod( 'logo_image' ) ); ?>' /> <?php bloginfo( 'name' ); ?> </h1>
<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
</a>

  • Site Division
    • Site Builder, Child of Zeus

    @patrick

    Thanks but I finally got the if/else right. :slight_smile:

    if (get_theme_mod('logo_image'))
    { ?>
    <h1 <a class="site-title"><img src='<?php echo esc_url( get_theme_mod( 'logo_image' ) ); ?>' /> </h1>
    <?php
    }
    else
    { ?>
    <h1 class="site-title"><?php bloginfo( 'name' ); ?></h1>
    <?php } ?>
    <h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
    </a>

  • Predrag Dubajic
    • Support

    Hey @fla0,

    Glad to hear you managed to resolve this :slight_smile:

    I had a quick look at your code here and noticed few mistakes, your h1 tag was opened but not closed before opening a tag, and do you even need h1 holder around the image?

    Also why is the a tag closed after everything if it starts inside first if statement, and why using a tag if there is no link added to it?

    Just some notes to make this look better and it also benefits SEO if html is written correctly :slight_smile:

    Best regards,

    Predrag

  • Site Division
    • Site Builder, Child of Zeus

    @predrag Dubajic

    Thanks for the input. I understand not using the H1 tag for seo but just didn’t have the time to style the logo so it would sit in the right place. I also tried removing the a tag and closing it differently but the results were not sufficient. Could you rewrite the code, so I could see what you have in mind.

    I am as todays Whip talks about just a WP code hacker, its fun! :slight_smile:

  • Predrag Dubajic
    • Support

    Hey @fla0,

    Sorry for the delay here, hope you had a nice weekend.

    You might try using something like this:

    if (get_theme_mod('logo_image')) { ?>
    <h1><div class="site-title"><img src='<?php echo esc_url( get_theme_mod( 'logo_image' ) ); ?>' /></div></h1>
    <?php } else { ?>
    <h1 class="site-title"><?php bloginfo( 'name' ); ?></h1>
    <?php } ?>
    <h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>

    When writing your code I suggest using text editors like SublimeText, Atom, NetBeans or similar which will highlight your selectors and you will be able to see the errors in your code.

    Best regards,

    Predrag

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.