colorpress - Premium WordPress Theme
$49.99

ColorPress is a theme that lets you play with color! Now, you will not be restricted to using a few color schemes provided by the developer. You have all the colors to apply to your theme! Just pick your color and magic happens. The theme comes with a configurable slideshow, 3 blog layouts, dropdown menus and a load of other options that will rock your socks!

Wix.com

May
02

How to Make Random Header Images?

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.

This post was viewed 15,593 times

» 29 people left comments { Collapse all | Expand all }

  1. very useful information , buy why don’t you give answer of the questions of the reader here to show for all users in you site. BtW great tutorials

    Reply to this comment
  2. where exactly I should place the first php code – I understand that it’s in header, but where??

    Reply to this comment
  3. Great tips,very useful information for bloggers.

    Reply to this comment
  4. Thanx so much :)
    very useful tut

    Reply to this comment
  5. That’s a great, easy and useful.
    thanks so much.

    Reply to this comment
3 2 1 »

    3 Trackback(s)

  1. Jul 17, 2009: Random Header Image für Wordpress | http://yks.org/
  2. Feb 7, 2009: ?????? | Knowledge Base
  3. Nov 11, 2008: how-to-make-random-header-images | - BloggWpress -

» Leave a Comment!

Search :
Browse :
Archive :

$$$ Make Money $$$

Become an Affiliate

Welcome to Blog Oh! Blog's affiliate program! I personally invite you to make money by selling all of Blog Oh! Blog's Premium themes.

You will get a whopping 25% share on each sale generated through your affiliate link.

All you need to do is sign up as Blog Oh! Blog's affiliate, choose a banner, paste it on your website or blog and wait for sales to happen. It's as simple as that!

All affiliates will be paid on 10th of every month. Your affiliate earning needs to be a minimum $50 to get paid for each month.

Here is the sign up link and here are some banners to get you started!