Conditionally Display Image on Header.php
-
OK. Let me see if I can communicate this issue correctly.
My header.php displays an image using this code:
<img src="<?php echo esc_url(get_stylesheet_directory_uri() ); ?>/images/background.jpg" alt="background">"
This is good for all pages except page 404.php. If this page is being displayed, I would like the header to display a different image, using this code:
<img src="<?php echo esc_url(get_stylesheet_directory_uri() ); ?>/images/404bg.jpg" alt="404">
I tried using several “if else” statements, to no avail. The latest, which doesn’t work is:
<?php if (is_page('546')) { ?> <img src="<?php echo esc_url(get_stylesheet_directory_uri() ); ?>/images/404bg.jpg" alt="404"> } <?php else { ?> <img src="<?php echo esc_url(get_stylesheet_directory_uri() ); ?>/images/background.jpg" alt="background">" } ?>
Would appreciate if someone could look at this and advise how to solve the issue. Thanks!
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Conditionally Display Image on Header.php’ is closed to new replies.