On a site I'm designing (business site versus blog - static homepage, etc.) for a client I have 7 different top -level product/service pages which have the same layout except for a graphic that stretches across the top, below the horizontal navbar and above the page content. Everything up to and including the navbar will end up in the header.php.

I would like the graphic to be in the page template as opposed to being part of the page content that the clients could access via the TineMCE editor. I don't want to have to create 7 page templates just for different top graphics. Does that make sense?

I've come a long way with WP; I'm pretty solid with HTML and CSS but am a cutter/paster when I get to php, but I'm thinking I might be able to put some kind of if/then call in the page template basically saying "if service page, use servicehead.jpg; if customersupport page, use customerhead.jpg," etc.

Is this possible?

If so, could someone tell me how I would write the call?

Here is my current page.php code:

<?php get_header(); ?>
<div id="pagebg">
<div id="pageheads">
<img src="<?php bloginfo('template_url'); ?>/images/customerhead.jpg"
alt="" height="120" width="1020" border="0" /></div>
<div id="colL">

After the colL div I have the loop and then I call a sidebar and the footer.

I'm thinking I would put a call in the pageheads div?

Any help would be greatly appreciated!


2 Answers 2


You're looking for the function is_page() You could use the page id, the title or the slug in the function.

<?php if ( is_page('services') ) : ?>
<?php elseif ( is_page('customer') ) : ?>
<?php else : ?>
<?php endif; ?>

Another option is to use the post thumbnail feature from wordpress, then you can specify in the page which image you want on top (if you don't already use them). ( http://codex.wordpress.org/Post_Thumbnails )

  • Perfect! Exactly what i wanted -- the is_pages()-- it works beautifully! Thank You!
    – PVA
    Commented Jan 15, 2012 at 19:18

You can do that using custom fields like so..


$key = 'headerIMG';
$themeta = get_post_meta($post->ID, $key, TRUE);
if($themeta = '') {

then where ever you want the image to show up:

<img src="<?php echo $themeta; ?>" alt="<?php the_title(); ?>" />

Last thing.. when ever you create a page with a speical image
you need to enter the value "headerIMG" in a custom field and the image URL as its value...

A Reminder:
please remmeber to replace the default img url in the first code
with the default one you want to show on pages without special images in the header unless there are none... (even so.. i would link to a default image just to be on the safe side)..

Hope this helps. Cheers, Sagive.


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.