PrimePress Theme for WordPress Rotating Header Image

WordPress Page specific Header Images

I saw some people looking to display a different image on each WordPress Page instead of the site wide random images. Read on...

First, I'll give you the code and explain how it works. That way, you'll understand it better and can easily adapt it to your site.

The Code

<?php if (is_page('28')) { ?>
	<img src="<?php bloginfo('template_url'); ?>/headers/image1.jpg" width="920" alt="<?php bloginfo('name'); ?> header image" />
<?php } elseif (is_page('26')) { ?>
	<img src="<?php bloginfo('template_url'); ?>/headers/image2.jpg" width="920" alt="<?php bloginfo('name'); ?> header image" />
<?php } elseif (is_page('30')) { ?>
	<img src="<?php bloginfo('template_url'); ?>/headers/image3.jpg" width="920" alt="<?php bloginfo('name'); ?> header image" />
<?php } else { ?>
	<img src="<?php bloginfo('template_url'); ?>/rotating.php?image=<?php echo mt_rand(0,100); ?>" width="920" alt="<?php bloginfo('name'); ?> Rotating Header Image" title="<?php bloginfo('name'); ?> Random Header Image" />
<?php } ?>

I have 3 Pages here. With the above code, I'm telling the theme to display a given image on each of those 3 Pages and to display random images everywhere else.

  • 1st two lines tell the theme to display image1.jpg on a Page with ID 28.
  • next two lines tell it to display image2.jpg on a Page with ID 26 and so on.
  • Last two lines (marked in blue) tell it to display random images everywhere else.

How to

  1. Upload your header images into the headers folder in your PrimePress directory.
  2. Open your header-images.php in your WordPress theme editor, delete the already existing code and paste the above code block in there.
  3. Change the Page ID and the image file name according to your site. (parts marked in red)

Some Notes

Chances are, you want to do this on more than three pages. Just copy (duplicate) the lines marked in green, paste them right below (but above lines marked in blue) and change the ID and filename.

If you have permalinks turned on, you can also type in the post-slug in place of the Page IDs.

70 Comments

  1. Shankar says:

    Hi Ravi, thanks for this informative post. I like this theme….very neat and your examples make modifications possible. I would like to try it on a new website…will let you know once its done.

  2. Ravi Varma says:

    Thanks a lot Shankar…

  3. Sujata says:

    Hi Ravi, I’m brand new to all this, but thanks for a beautiful, clean design. I want to use two different pages for two different blogs, and I’d like to be able to have a separate set of blogrolls on each page (and, ideally, separate tag clouds and categories). Is this possible?

  4. Ravi Varma says:

    Hi Sujata,
    While I can not say its not possible, it becomes rather convoluted. I’d say the ideal way to maintain two blogs is to install two blogs and link them together.

  5. Hi Ravi,

    That’s great! Thanks for telling us how to do it. :-)

  6. Jose HC says:

    Hi Ravi,
    I just started a little blog to keep family and friends posted and I wanted to tell you that I must have looked at nearly 100 themes and for whatever reason kept coming back to this one. It is nice and clean; easy on the eyes. I just need to get around to changing the pictures and it is good to go!

    I also wanted to let you know that I found that article (I guess the only one up) on your TechTrot site useful for someone starting out. You should write a little more often over there.

    Cheers,
    Jose

  7. [...] WordPress Page specific Header Images – PrimePress Theme for WordPress [...]

  8. Jim says:

    Ravi,

    Very nice use of the switch. I think this is what I need, here is what I want to do. On my contact form page ( plugin used for form ) I want to add an image to the page. If i put the php for the image in my ( page.php ) file it shows up on all pages. I just want it on the contact page. ALSO, in Wordpress 2.7 page id’s are not listed in Admin Edit pages.

    Thanks for any info that might help.

    Jim

  9. Jim says:

    Very nice use of the switch. I think this is what I need, here is what I want to do. On my contact form page ( plugin used for form ) I want to add an image to the page. If i put the php for the image in my ( page.php ) file it shows up on all pages. I just want it on the contact page. ALSO, in Wordpress 2.7 page id’s are not listed in Admin Edit pages.

    Sorry-forgot to say. As you mentioned above might be easier to use slug (contact) since page id’s are not displayed any longer. My image path is ( images/logo.png)

    Thanks

    JIM

  10. dee yan says:

    This codes which i’ve been looking for, thanks Ravi

  11. WOW that code is extremely simple thanks so much.

  12. zaarco says:

    i use it but have some troubles with colors identification =((

  13. Great work!

    Was asked if I could add this feature to a site today, obviously I said “of course” but had no idea how I was going to do it!

    Many thanks

  14. Hello:)

    That post solve my problem – thanks a lot:)

    Best Regards

  15. Arefom says:

    Yeah, now it is understandable … And then I just not even know where it is not us with the title …

  16. RaiulBaztepo says:

    Hello!
    Very Interesting post! Thank you for such interesting resource!
    PS: Sorry for my bad english, I’v just started to learn this language ;)
    See you!
    Your, Raiul Baztepo

  17. Mira says:

    Very nice use of the switch. I think this is what I need, here is what I want to do. On my contact form page ( plugin used for form ) I want to add an image to the page. If i put the php for the image in my ( page.php ) file it shows up on all pages. I just want it on the contact page. ALSO, in Wordpress 2.7 page id’s are not listed in Admin Edit pages.

    Thanks for any info that might help.

  18. Todd Dawson says:

    I’m trying to set up the blog so a specific image always shows up on each page, and used your code for doing this. Problem is, I can’t find how the home page is labeled… it doesn’t show up on the “Edit Pages” page… How would I find this out? I’ve tried all possible permutations (index, home, homepage, default, etc).

  19. Sweercearelp says:

    а вот вопросик можно? У вас время после поста указано. Это московское? Заранее спасибо!

  20. ravi says:

    helped me very much. thanks

  21. borya874 says:

    Мне нравятся Ваши посты, заставляет задуматься…

  22. gor5557 says:

    не информативно как- то

  23. Ornaltyreera says:

    большое спасибо!Взяла себе тоже-пригодится.

  24. nnm7773 says:

    Мне кажется очень хорошо

  25. gosha587 says:

    Мне кажется ништяк!

  26. Fruing says:

    Опубликовал на своем блоге вашу статью, и напечатол там конечно-же обратную ссылку на вас. Но вот зашел посмотреть поевился ли трекбек, а его нет…

  27. [...] * WordPress page specific header images [...]

  28. Mike says:

    Finally! Someone with a little know-how! Thank you so much for this post.

  29. [...] on the header and other post pages, but on individual pages as well), I came across this post from Ravi Varma. It helped me do exactly what I wanted and it was super-easy too! Here’s how you change an [...]

  30. Nathaniel Chang says:

    this is great but I can only get it to work on pages like is_home and is_search, giving ids just doesn’t show the images or even a placeholder, can you help?

  31. И как же это можно понять простому человеку?

  32. Тяжело в учении – легко… в учебном бою.

  33. Голова трещит. Следует что-либо предпринимать в своем бизнесе. Да и грядущая перерегистрация ООО – очень актуальная тема на сегодняшний момент. Не профукать бы. Проблему необходимо решить за полгода. Крамбец.

  34. Горы мусора ещё не баррикады, – СВОБОДЫ не хватает!

  35. Отличный пост. Я вот тоже хочу поделиться полезной ссылкой. Тут можно скачать программу. Так что заходите – не пожалеете.

  36. Складно пишете. Но не пойму почему изложеный материал вызвала воспоминания о детстве, и не отходя от темы – Детские Игрушки Москва. И не забрасывайте блог; )

  37. Do you want know your dns records tools?

  38. Cool servise – My-Addr Project

  39. Thanks for the fascinating code and steps! I have been searching for this for almost 2 hours now, thanks.

    Regards,
    Jermaine

  40. Aaron says:

    Hi Ravi,
    Thanks for a great theme! I wanted to know if it is possible to adapt this function to create page specific banners in the wide sidebar? And if it is possible to add links to them as well?
    Any advice would be much appreciated.
    Thanks,
    Aaron

  41. Ellis Benus says:

    I sure wish someone would write a plug in to add this functionality.

    I think I’m going to have to tackle that…

  42. [...] * WordPress page specific header images [...]

  43. Hey, you must see that – replica tag heuer

  44. Newbie says:

    I’m very green at this. Can you tell me how to upload the header images? Thnx!

  45. tatil says:

    thank you very good

  46. Смотреть фильмы онлайн

  47. Daddy23 says:

    They scream at each other, exchange racial epithets, and, in some cases, incite fights. ,

  48. Roy12 says:

    Even though members can be academic experts and researchers, Yahoo! ,

  49. Change the Page ID and the image file name according to your site. (parts marked in red)
    what is page id?

  50. flood says:

    Big thanks…)

  51. Thanks!) good site..

  52. Fartt says:

    Thanks for the fascinating code and steps! I have been searching for this for almost 2 hours now, thanks.

  53. Alejandro says:

    Hi Ravi… Excellent post, but I have a little question:

    Could I replace this on this to specify a concret category where I need to show a specific image. Thanks a lot man!

  54. Текст реально понравился. Автору респект и уважуха. В поддержку темы тоже делюсь тем, что близко мне – Скандальные новости мира, Заходите – не пожалеете

  55. Oleksiy says:

    Very smart post! Thank you!

  56. YRSS

  57. You must see that – dumps

  58. Думаю всем читателям этого ресурса будет полезна следующая ссылка – болезни поджелудочной железы

  59. thnx admn

  60. thank you admn

  61. Thanks for the advice, brilliant

  62. this is the best site for machines

  63. ahmet ertem says:

    asdasdas

  64. thanks for your information…

  65. Ipad says:

    I use this theme in my blog —-> www. redtor. com

  66. NetboyMusic says:

    Hi admin,

    That’s great Theme! It’s Easy to use and I use this theme in my blog…

  67. Vladimir says:

    скачать сериалы

  68. Vladimir says:

    kluchi

  69. Vladimir2 says:

    аквариумы

  70. Smith says:

    Thanks! good site.. Good Theme!

Leave a Reply

  • Donate to PrimePress

    If you are happy with the theme and would like to make a donation, please use the button below. Thank you for supporting the development of PrimePress.

  • Recommended Host

    If you are looking for a good web-host, Dreamhost is among the best out there. Apart from the great stuff they offer, Dreamhost's got a hassle-free hosting environemnt ideal for WordPress. Type in PRIMEPRESS as the promo code to save US$50 while signing-up.