PreviousPauseNext
Latest Free WordPress Themes | More Free Themes
DailyPress WordPress Theme
DailyPress

Minimalistic Theme
125x125 Ad Space
Widgets Ready
Social Tagging
Tabbed Sidebar
XHTML Compliant

Demo
Download
Latest Free WordPress Themes | More Free Themes
Firebug WordPress Theme
Firebug

Colorful Theme
125x125 Ad Space
Widgets Ready
Social Tagging
Gravatar Ready
XHTML Compliant

Demo
Download
Latest Free WordPress Themes | More Free Themes
Gridblog WordPress Theme
Gridblog

Minimalistic Design
WP Gallery Ready
Gravatar Ready
Grid Based
Widget Ready
XHTML Compliant

Demo
Download
Latest Free WordPress Themes | More Free Themes
Blue Weed WordPress Theme
Blue Weed

WP 2.5 Gallery Compatible
Adsense Ready
Gravatar Ready
3-Columns
Widget Ready
Logo PSD

Demo
Download
Latest Free WordPress Themes | More Free Themes
AdsPress WordPress Theme
AdsPress

WP 2.5 Gallery Compatible
Adsense Ready
Gravatar Ready
2-Columns
Widget-Ready
Logo PSD

Demo
Download
Latest Free WordPress Themes | More Free Themes
Statement WordPress Theme
Statement

WP 2.5 Gallery Compatible
Quick Tabs
100% Width
3-Columns
Widget-Ready
Logo PSD

Demo
Download
Latest Free WordPress Themes | More Free Themes
Tutorials WordPress Theme
Tutorial Theme

Tutorials Feature
Thumbnails
Bright colors
3-Columns
Widget-Ready
XHTML Compliant

Demo
Download
Latest Free WordPress Themes | More Free Themes
Corptheme WordPress Theme
Corptheme

Four Flavors
Dropdown Menu
Separate Trackbacks
3-Columns
Widget-Ready
XHTML Compliant

Demo
Download
Latest Free WordPress Themes | More Free Themes
Chronicles WordPress Theme
Chronicles

Dark Brown
3-Columns
Widget-Ready
XHTML Compliant
Web 2.0

Demo
Download
Latest Free WordPress Themes | More Free Themes
Velocity WordPress Theme
Velocity

Trackbacks & Comments
3-Columns
Widget Ready
XHTML Compliant
Web 2.0

Demo
Download
Latest Free WordPress Themes | More Free Themes
Blue Lily Theme
Blue Lily

3-Column
Widget Ready
XHTML Compliant
Web 2.0
Rounded Edges

Demo
Download
Latest Free WordPress Themes | More Free Themes
Techicon Theme
Techicon

4-Column
Widget Ready
XHTML Compliant
Blue/White
Recent Boxes

Demo
Download
Latest Free WordPress Themes | More Free Themes
Brilliance Theme
Brilliance

3-Column
Widget Ready
XHTML Compliant
Black/White
Adsense Ready

Demo
Download
Latest Free WordPress Themes | More Free Themes
Identity Theme
Identity

3-Column
Widget Ready
XHTML Compliant
Black/White
Rounded Edges

Demo
Download
Latest Free WordPress Themes | More Free Themes
Xplosive Reloaded Theme
Xplosive Reloaded

3-Column
Widget Ready
XHTML Compliant
Multi-colored
CSS Style Switcher

Demo
Download
Latest Free WordPress Themes | More Free Themes
Limit Theme
Limit

3-Column
Widget Ready
XHTML Compliant
Blue/White
Rounded Edges

Demo
Download

How to Make Random Header Images?

Written by Jai on May 2, 2008 – 12:14 pm - 5,633 views

Random Header Tutorial

You are using a neat WordPress theme with an image header but want to have multiple images that you can randomize on your blog? Here is how to go about it…

STEP 1 - Editing Images

Make all your header images that you want to randomize of the same size (dimensions) and format. For example, if you have GIF images then all should be of the same extension. I hope you get the point.

STEP 2 - Naming Images

All the names of your header images should follow a similar pattern. Here is an example we will use :-

blogtop-1.gif
blogtop-2.gif
blogtop-3.gif
blogtop-4.gif

We do this because when writing the code, we will try to randomize the number part (logically, randomization is done by numbers in any programming language) and keep the text part similar for all.

STEP 3 - Moving the Image Files

Move all your header image files to the “images” folder in your theme folder. Most probably, if you are using a theme that uses images, then it should have an “images” sub-folder. If not, make one and put all your header images in there.

STEP 4 - Randomizing the Images

Open your header.php file from the theme folder in a text editor. Put this code just below the tag.

<?php
$header_image = rand(1,4);
?>

The rand() function actually picks up a random number from the number of items you have specified. We are going to use this function to randomize and pick 1 item from the 4 header images in the “images” folder. So, if you have more than four images, just change 4 to your number.

STEP 5 - Using the Randomization in the Actual Header

This part can be a bit tricky as it will require you to find the code where your theme calls the actual header image (the one being used in the default theme). Usually, most of the professional theme designers define the header image through the CSS background property of the header DIV. So, you will have to get rid of that technique and use the old school HTML technique to call the image in the header DIV or the place where you want your header image to be located.

Ideally, the following piece of code will pull your header images in your theme :-

<img src="<? bloginfo('template_directory'); ?>/images/blogtop-<? echo $header_image; ?>.gif" alt="header" />

So, basically this code will insert the value of the variable $header_image after “blogtop-” and this will pull out the image from the “images” folder. All you have to do is figure out where exactly to place this img code in your theme header.

This concludes the random header tutorial and if you have questions, just ask here in the comments.

If you enjoyed this post, make sure you subscribe to my RSS feed!


21 Responses to “How to Make Random Header Images?”

  1. Very useful.I can make some header images by myself


    Reply to this comment

  2. Nice tutorial, Jai. BTW, currently I am using Silver Light theme. How do I insert or change the header file so I can replace the title to an image of my choice? Thanks


    Reply to this comment

  3. good tutorial, useful for me.
    thxs


    Reply to this comment

  4. Great little tutorial here. I knew that it had to be pretty easy, but I hadn’t had a reason to use random images yet. Thanks for the info!


    Reply to this comment

  5. It’s a great job, easy and useful, thks.


    Reply to this comment

  6. i am using a script that does this, and i looked for months before i found it….I call my pap code in the css itself though….


    Reply to this comment

  7. Thanks for this code. Been reading your blog post for quite some time now, silently.. and I have to say, No regret. Thanks once again, Jai ;)


    Reply to this comment

  8. Pretty Simple, but useful!
    Thanks


    Reply to this comment

  9. Wow, that’s a great idea. I should be able to do that by myself, although I’m a noob :) But I like how that looks like, definitely.


    Reply to this comment

  10. Nice tutorial. I used a similar method on a vBulletin forum a while back, with great results.


    Reply to this comment

  11. Good article, Thanks. I will take a minute for doing in my blog. Uoppps, thanks a lot. Great jobs


    Reply to this comment

  12. I am not able to under stand the 5th stage. you can visit my site to see the theme I am using.


    Reply to this comment

  13. thats very useful, thanks so much.


    Reply to this comment

  14. Great tips, I might create few header and let it randomly load, let my reader feel not so bored after view my blog…

    I also might create season header, like new year, or xmas… and let it random load…


    Reply to this comment

  15. Hello, my web site using freshy theme. And I can’t do the Step 5.
    I have to put that code on the header.php
    Or I have to find that code in the header.php and change it?
    And what do I do with the css file?


    Reply to this comment

  16. This tutorial is cool and i wanna use it for:
    http://www.deskbeauty.com


    Reply to this comment

  17. good!!!!!!!


    Reply to this comment

  1. 4 Trackback(s)

  2. Randomizando o topo do seu blog : Peru não pia
  3. jaehong75.com : links for 2008-05-03
  4. ?wp???????????? | ??-Do it win yourself
  5. Como fazer “headers” aleatórias?

Post a Comment