user2684025
user2684025

Reputation: 25

Wordpress using Conditional Tags to publish different logo

I like to show different logo on two different page but keep the original logo on front page and the rest of the site. So I try with wordpress conditional tag but It doesn't work. Someone can help me?

Thank you.

<?php if ( ! is_front_page() ) {?>
<img class="logo-top" src="image1" alt="image1">
<?php } ?>

<?php elseif ( ! is_page(157) ) {?>
<img class="logo-top" src="image2" alt="image2">
<?php } ?>

<?php elseif ( ! is_page(157) ) {?>
<img class="logo-top" src="image3" alt="image3">
<?php } ?>

<?php else ( ) ) {?>
<img class="logo-top" src="image1" alt="image1">
<?php } ?>

<?php endif; ?>

Upvotes: 0

Views: 447

Answers (3)

user2684025
user2684025

Reputation: 25

Here the solution I found. Thanks.

<?php
if ( is_front_page() ) {
// Default homepage
echo ('<img class="logo-top" src="image1" alt="image1">');
} 
elseif ( is_page( 157 )  ) {
// landingpage1
echo ('<img class="logo-top" src="image2" alt="image2">');
} 
elseif ( is_page( 159 ) ) {
// Landingpage2  
echo ('<img class="logo-top" src="image3" alt="image3">');
} 
else {
// All other page 
echo ('<img class="logo-top" src="image1" alt="image1">');
}?>`

Upvotes: 0

vaso123
vaso123

Reputation: 12391

The correct syntax is:

<?php if (!is_front_page()) { ?>
    <img class="logo-top" src="image1" alt="image1">
<?php } elseif (!is_page(157) ) { ?>
    <img class="logo-top" src="image2" alt="image2">
<?php } elseif (!is_page(157) ) { ?> <!-- Why is this the same id? Never will be executed  -->
    <img class="logo-top" src="image3" alt="image3">
<?php } else { ?>
    <img class="logo-top" src="image1" alt="image1">
<?php } 

Upvotes: 1

Nico
Nico

Reputation: 6893

I see two problem.

  1. <?php else ( ) ) {?> should be <?php else {?>
  2. There is no need for <?php endif; ?>.

Upvotes: 0

Related Questions