25 Jun, 2009
How to display a different header image for different pages in WordPress
In header.php file of my WordPress theme, I have the following code to display a different header image for different pages.
<?php
if (is_page('about')) {
$image = 'image_about.jpg';
} else if (is_page('projects')) {
$image = 'image_projects.jpg';
} else if (is_page('services')) {
$image = 'image_services.jpg';
} else if (is_page('contact')) {
$image = 'image_contact.jpg';
} else {
$image = 'image_default.jpg';
}
?>
<div id="header">
<img src="<?php echo bloginfo('template_url'); ?>
/images/<?php echo $image;?>"
alt="<?php bloginfo('name'); ?>" />
</div>
Love what you've just read? Subscribe to our newsletter to receive tips, resources and special offers related to web development & design.
Other similar posts that you might be interested in:
- How to customise WordPress Admin Login page
- Customising category.php in WordPress
- 5 steps to creating a custom Archive page in WordPress
- Display 5 latest posts in each category in WordPress
- How to add a breadcrumb to your blog and have it appear on Google’s Search Result Snippet
- Golden Green WordPress Theme – Download
- Building a real estate website using WordPress
Hello! Welcome to Web development blog! My name is Ei Sabai and on this blog, I write about web development, mobile app development, latest web technologies and the likes. Read more 


Thanks a lot !
I think this tip is useful for the magazine blog.
My site is also an magazine blog so I just need this tip.
i love this, thanks
Hi, can I show also a swf file?? I think yes, but I want to know your opinion before the creation of the flash file.
Thanks
Nick: Yes, you can. If you have different flash files for different pages of the website, you can use the same code but replace the name of the image with the name of the flash file (eg: instead of image_about.jpg, it will be about.swf). And then you will need to change your flash embed code (eg: swfobject) to use the variable that you specified.
Thanks man , i was looking for this !!!
.-= jean paul´s last blog ..Palais des thés =-.
This code is not working for my “blog” page…!!!! Why??? for other pages code is working as described.
Thank you so much!