I was just presented with a project that called for a different header on each page. With around 50 pages to consoder, I needed a piece of code that would make life easy. This nugget will call a different header depending on the name of the slug for the page. For this code to work “out of the box”, you must name the slug of each WordPress page the same as you name the image that you save in your WordPress library. IE. a page with the slug contactus will need an image that is also named contactus. The images also have to be saved in jpg format for this to work as is. Other than that, here ya go
$getPage = $post->post_name;
$imagePath = ABSPATH . ‘wp-content/uploads/2013/04/’.$getPage.’.jpg’;
echo ‘<img class=”customBanner” src=”../wp-content/uploads/2013/04/’.$getPage.’.jpg”/>’;
echo ‘<img class=”customBanner” src=”../wp-content/uploads/2013/04/media.jpg”/>’;
as you can see from the code above, I excluded the home page. Rather than explicitly stating which page you would like to include, you can replace that with WordPress’s built-in function is_front_page(). Other than that, it’s pretty straightforward. Your else statement is the image that will be displayed if the first file is not found.
That should do it!