typo_
typo_

Reputation: 21

how to properly replace logo with text in header

In header.php have a code that insert a logo into the place:

<div class="small-7 medium-4 columns logo<?php if ($header_style == 'style1') { ?> show-for-large-up<?php } ?>">
                <?php if ($header_style == 'style2') { ?>
                    <a href="<?php echo home_url(); ?>" class="logolink">
                        <img src="<?php echo $logo; ?>" class="logoimg" alt="<?php bloginfo('name'); ?>"/>
                    </a>
                <?php } ?>
            </div>

(upper left corner):

In order to have a logotext instead of the png file, I've used the following code with no errors in the console but I'm pretty insecure being a noob in php coding. Is this the proper way (incuding the indentation) to have the desired result ?

<div class="small-7 medium-4 columns logo<?php if ($header_style == 'style1') { ?> show-for-large-up<?php } ?>">
                <?php if ($header_style == 'style2') { ?>
                    <a class="logotext" href="<?php echo esc_url( home_url( '/' ) ); ?>"
                    title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"
                    rel="home"><?php bloginfo( 'name' ); ?>
                    </a>
                <?php } ?>
            </div>

Upvotes: 0

Views: 140

Answers (1)

Wali Hassan
Wali Hassan

Reputation: 480

You are doing it right and I hope you're doing it in the child theme.

Here is more refined version of your code which will render Blog Title or text logo in case you don't have the Image Logo uploaded. If, however, the image logo is uploaded, it will use image.

<div class="small-7 medium-4 columns logo<?php if ($header_style == 'style1') { ?> show-for-large-up<?php } ?>">
            <?php if ($header_style == 'style2') { ?>
            <?php if (empty($logo)) { ?>                
             <a class="logotext" href="<?php echo esc_url( home_url( '/' ) ); ?>"
                title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"
                rel="home"><?php bloginfo( 'name' ); ?>
                </a>                
            <?php }else{ ?>
               <a href="<?php echo home_url(); ?>" class="logolink">
                    <img src="<?php echo $logo; ?>" class="logoimg" alt="<?php bloginfo('name'); ?>"/>
                </a>
            <?php } ?>
            <?php } ?>
        </div>

Upvotes: 1

Related Questions