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.

120 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.

    1. Insurance says:

      Its nice theme. I installed it on my blog today. Thanks.

  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).

    1. Geoff says:

      Put the images into a subfolder in the headers folder

      headers/pages/image-home-page.gif
      headers/pages/image-contact-page.gif

      etc

      this keeps them out of the rotation images, which only looks in the main ‘headers’ folder not subfolder.

      So you can choose which pages for individual images, and have 1 in rotating images ‘headers’ folder; or 4 or whatever, as the default for ‘general’ pages.

      Thanks

  19. Sweercearelp says:

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

  20. ravi says:

    helped me very much. thanks

    1. Sharky says:

      The forum is a brgheitr place thanks to your posts. 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. Thanks for the fascinating code and steps! I have been searching for this for almost 2 hours now, thanks.

    Regards,
    Jermaine

  38. 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

  39. 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…

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

  41. Newbie says:

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

  42. tatil says:

    thank you very good

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

  44. Daddy23 says:

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

  45. Roy12 says:

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

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

  47. flood says:

    Big thanks…)

  48. Fartt says:

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

  49. 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!

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

  51. Oleksiy says:

    Very smart post! Thank you!

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

  53. Thanks for the advice, brilliant

  54. this is the best site for machines

  55. thanks for your information…

  56. Ipad says:

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

  57. NetboyMusic says:

    Hi admin,

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

  58. Smith says:

    Thanks! good site.. Good Theme!

  59. A big thank you for the information

  60. Havuz says:

    thanks for useful and meaningful article…:

  61. Instyler says:

    Thanks Ravi for this great tip. I really like your theme and I’ve used it a few times. Can this technique be used in sidebar ads as well?

  62. firman says:

    where is the header folder in primepress directory???

  63. Diksha says:

    I have used the same thing to change the banner images for different pages and they are changed also but for particular one page which has job board plugin and is also based on separate template page rather than default template,for it I am not able to change its banner. It is showing the default banner which I have used in else statement

  64. alanbernard says:

    Hey guys,

    For everyone looking for the solution to the home page, this is what I did.

    <img src="/headers/image1.jpg” width=”920″ alt=” header image” />

    I changed that to:-

    <img src="/headers/image1.jpg” width=”920″ alt=” header image” />

    That’s it. Hope that helps someone. :)

    1. alanbernard says:

      <img src="/headers/image1.jpg” width=”920″ alt=” header image” />

      change to:-

      <img src="/headers/image1.jpg” width=”920″ alt=” header image” />

      *please remove spaces between the < & ?

  65. alanbernard says:

    Shit, I can’t post php here, but basically you need to change the first line of code from if is_page to is_home and that’s it.

    1. fabio says:

      thank you now i had only a problem in te POST the hedler is broken can you help me?? Thanks

  66. Вполне, ч0ткая новость

  67. Пежо says:

    Не помню где я уже читал близкую инфу да ладно

  68. MaRarts says:

    Писака респект

  69. 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.

  70. Havuz says:

    Shit, I can’t post php here, but basically you need to change the first line of code from if is_page to is_home and that’s it.

  71. Hi , Thanks very good logo tasarım , puna , kısmetim 2follow me web sites . Thank you

  72. I am very happy I found this article. Thanks for the post!

  73. alamin says:

    Great post also! Your writing is so fresh in comparison to most other bloggers. Thanks for writing when you get the chance to, I’ll be sure to keep visiting!

    Thanks
    Md.Alamin Khan

  74. liton says:

    Great article on social media. This article points out some good information about how social media is a big factor on business

    Thanks
    Liton mia

  75. bivian says:

    Your article seems interesting, i have noted it my digg and stumble account.The point you are making is easy to understand and effective. I have blog site for SEO, Art,Shopping.

    Thanks
    bivian tilma

  76. romal says:

    Hello there ,
    this is a very interesting article. I tell you that the subject is more profound that appear. Believe me !!! Very good site.Keep it up.I liked the look and feel of ur site. . I have many blog site for Link, directory,Hosting
    ,Sports and much more.

    Best of luck
    Romel Naan

  77. Ellis Benus says:

    > Ellis Benus posted on July 17, 2009 at 12:51 pm:
    > I sure wish someone would write a plug in to add this functionality.
    > I think I’m going to have to tackle that…

    Well, good job core WordPress team. :-)

  78. Михаил says:

    Автор перспективный мужик

  79. Чего и следовало ожидать, тот кто писал убого опубликовал.

  80. I am going to give it a try, I will use that switch on my theme

    Thanks a log Ravi

  81. çocuk montu says:

    Thanks! good site.. Good Theme!

  82. peruk says:

    Your article seems interesting. Thank you very much.

  83. Мысль никогда не должна подчиняться ни догме, ни направлению, ни страсти, ни интересу, ни предвзятой идее, ни чему бы то ни было, кроме фактов, потому что для нее подчинится — значило бы перестать существовать.

  84. Квартиры в Москве от застройщика – это наиболее популярный и выгодный вариант при покупке жилья на сегодняшний день. Готовые квартиры в новостройках Москвы – это дома, построенные совсем недавно.

  85. prefabrik says:

    I am going to give it a try, I will use that switch on my theme

  86. I will use that switch on my theme

  87. implant diş says:

    thank you very good nice works good

  88. nedenleri says:

    theme colors and a very good initiative. You know google argoritmasına new understanding and appropriate

  89. narsimha says:

    WOW that code is extremely simple thanks so much.

  90. Gaurav says:

    thanks buddy… code is succesfully runing…. keep rockin…

  91. zlobaz says:

    Хороший блог, только вот шрифт слегка напрягает глаза при чтении, но в целом немало времени провёл здесь, добавил в закладки :-)

  92. altin çilek says:

    Your article seems interesting. Thank you very much.

  93. Aparna says:

    Thank you for this code.

  94. header image says:

    I would appreciate your comment on this:
    Header graphics are perhaps not as important on a website as they once were?
    I know this may appear to be controversial, but I believe that we are now seeing a trend that we have not seen before. Do you agree or disagree? I am not changing the subject it just that I think we need to expand the conversation.

  95. Rajdip says:

    Thanks a Lot Mr. Ravi Sharma…Vry Nice Article ..Keep it Up

  96. would appreciate your comment on this:

  97. Finance says:

    Can you help me set this up

  • 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.