How to rotate the header image per day?

I’d like to have my header banner change every day, chosen (e.g. randomly) from a list/folder of images.

So far I only found plugins that select a random banner per post or per page view, neither is what I want. Do you know of a plugin, or any other way?

Read More

Edit: Example. I’m adding a folder to my wordpress installation. This folder contains some header images. Every 24 hours, an random image is chosen from this folder and becomes the header image for 24 hours, until another random image is chosen.

Actually, I don’t care how exactly the image is chosen – I’m fine with rotating through all images in the folder as well. The only thing I care about is that the chosen image stays there for 24 hours.

Basically it’s the same as if I were picking a new header image manually every day.

Related posts

Leave a Reply

5 comments

  1.  <div id="header">
        <?php
            mt_srand((int)date('z'));
            $headers=glob(PATH_TO_FILES .'/*.jpg');
    
            $header=mt_rand(0,count($headers)-1  );
            ?>
                <img id="header-image"  `src="<?php echo URL_TO_FILES . '/'.basename($headers[$header]);  ?>" alt="header" />
    
    
    
    
     </div>
    

    replace your current header with this. I will of course help you implement this further if you need help. (or if you need the code explained)

  2. Based on Cronco’s answer and a lot of experimentation (I’m neither familiar with PHP nor with the inner workings of wordpress itself) and some cleanup, I found a solution that perfectly satisfies my needs.

    Using the theme TwentyTen, I edited its header.php like this:

    <?php
        // Check if this is a post or page, if it has a thumbnail, and if it's a big one
        if ( is_singular() &&
                has_post_thumbnail( $post->ID ) &&
                ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) &&
                $image[1] >= HEADER_IMAGE_WIDTH ) :
            // Houston, we have a new header image!
            echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
        else : ?>
    
            <!-- patch mafu begin -->
            <?php
            $headers = glob( get_template_directory() . '/banners/*.jpg' );
            $header = (int)date('z') % count($headers);
            ?>
            <img src="<?php echo get_template_directory_uri() . '/banners/' . basename($headers[$header]); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
            <!-- patch mafu end -->
    
        <?php endif; ?>
    

    If no specific image is set for the displayed page (this is specific to this theme), then a header image is chosen based on the current day from all jpg images in the theme_directory/banners folder, which has to be created.

    I tried to randomize the image order more, but apparently this is not possible in an easy way, so I went with fixed order.