Dynamic, changing header images a possibility?

  • Unknown's avatar

    Since I have created several header images over the past few months on WP, it would be great to be able to tweak templates to randomly choose an image for that space from a folder, and having it change with refreshes, rather than having a static header.

    Anyone doing this?

    Thanks, Bronson

  • Unknown's avatar

    To do that you need a simple script, and since we do not have access to those files/can add any I can’t see how it can be done.

  • It can be done with CSS and the Sandbox theme. The Diurnal style for Sandbox changes its header based on the time of day:

    http://sndbx.org/results/designs/diurnal/

    With a little imagination you could use a similar technique to make it change each time the page is refreshed.

  • Unknown's avatar

    Probably, if random is good enough for you – you can just paste a bit of php-code in your header.php. Open header.php, look for the html code that shows your header-image.

    It might look something like this :

    <img src=”<?php bloginfo(‘template_directory’); ?>/img/header.jpg”>

    You want to add something like this : <?php echo(rand(1,4)); ?>
    Just add that bit of code to the image path like this :

    <img src=”<?php bloginfo(‘template_directory’); ?>/img/header<?php echo(rand(1,4)); ?>.jpg”>

    The code snippet gives a random-number from 1 to 5. Just modify it to whatever you want. Since it’s random, this code now uses any one of these images as it’s header :

    header1.jpg
    header2.jpg
    header3.jpg
    header4.jpg

    So make sure you have these. Just modify the code for more or less headers and upload / rename the ones you’re using and that’s it. Random headers, simple as can be!

  • Unknown's avatar

    “The code snippet gives a random-number from 1 to 5.”

    Huh, I meant from 1 to 4 of course .. hopefully, that should already be appearant. :)

  • Unknown's avatar

    We don’t have access to the php files here at WordPress.com. That’s why these kinds of changes are difficult.

  • The topic ‘Dynamic, changing header images a possibility?’ is closed to new replies.