0

This is my Theme code to call custom logo

<!--======= LOGO =========-->
  <div class="logo"> 
    <?php $log_url = sh_set( $options, 'site_logo', get_template_directory_uri().'/images/logo.png' );
          $log_url = ( $log_url ) ? $log_url : get_template_directory_uri().'/images/logo.png';
          $logo_size = @getimagesize($log_url); //printr($logo_size); ?>
    <a title="<?php echo esc_attr(get_bloginfo('name')); ?>" href="<?php echo esc_url(home_url()); ?>">
        <img src="<?php echo esc_url($log_url); ?>" alt="<?php echo esc_attr(get_bloginfo('name')); ?>"  width="<?php echo sh_set( $logo_size, 0); ?>" height="<?php echo sh_set( $logo_size, 1); ?>" >
    </a> 
  </div>

Trying to add ability to call a different logo image for different Page's. I found this snippet but can't seem to get it to work.

If (is_front() || is_home) {
//Your logo for the front page
}
Else {
// Your other logo
}

By calling:

is_page( array( 42, 54, 6, etc ) )

Don't do this for a living so just can't completely wrap my head around it.

4
  • Is the code above exactly what you tried? If not, please correct it, because your snippet ( if else ) has wrong syntax.
    – Tung Du
    Commented Sep 29, 2018 at 2:20
  • Sorry Tung, is it correct now?
    – Joe
    Commented Sep 29, 2018 at 2:24
  • @Joe, use is_front_page() and not 'is_front()'; and is_home() and not just 'is_home'.
    – Sally CJ
    Commented Sep 29, 2018 at 2:35
  • You could either use the default page thumbnail for your logo, or you could use a plugin like Advanced Custom Fields to add a custom logo uploader field to your page edit screen. Then simply display those images in your page template. Hard coding page Id's in your templates is harder to maintain.
    – Hans
    Commented Sep 29, 2018 at 10:53

1 Answer 1

0

Try this below code your active theme.

$logo = sh_set( $options, 'site_logo', get_template_directory_uri().'/images/logo.png' );
$logo_other = sh_set( $options, 'site_logo', get_template_directory_uri().'/images/logo1.png' );
if (is_page( 42 ) || is_page( 54 ) || is_page( 6 ) || is_page( 8 ) || is_page( 15 ) || is_page( 66 ))
{

    echo '<div class="site-logo"><a href="'. esc_url( home_url( '/' ) ) .'">';
    echo '<img calss="mylogo1" title="'. get_bloginfo('name') .'" src="' . $logo_other .'" />';
    echo '</a></div>';

}
else
{

    echo '<div class="site-logo"><a href="'. esc_url( home_url( '/' ) ) .'">';
    echo '<img calss="mylogo2" title="'. get_bloginfo('name') .'" src="' . $logo .'" />';
    echo '</a></div>';
}
2
  • Instead of repeated is_page() calls (is_page() || is_page() || is_page() ...), you should use is_page( array( 42, 54, 6, 8, 15, 66 ) ) - i.e. pass an array of page IDs.
    – Sally CJ
    Commented Sep 29, 2018 at 5:26
  • I have try this is_page array concept but it's not working from our end. so that i suggest separate is_page()
    – VinothRaja
    Commented Sep 29, 2018 at 5:40

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.