Please note: This page contains affiliate links. If you purchase from a partnership site, I may earn a commission.

Display an image according to the month name using javascript

Written by: | Published: June 10, 2010 | Updated: April 19, 2023

Having content that changes dynamically (on it’s own according to some criteria) is a great way to add some extra interest and diversity to your site without the added time to maintain. Scripts can automatically change various aspects of your site without you doing a thing once the script is installed. This script will display an image depending on what month it is, and will automatically update the image as soon as the month changes.

To use:
Upload GIF images named each month, January.gif, February.gif, etc.

Change the following url in the code below to the location you uploaded all your images:
https://www.YOURDOMAIN.com/DIRECTORY-WITH-IMAGES/

Add the following code to the header of your page or site template for your site.
This code also works for Cafepress. Simply include this code either in your custom html layout header area OR, I have it in my “store description” area of my premium shop.

<!-- START CODE -->
<script>

var d=new Date()

var month=new Array(12)
month[0]="January"
month[1]="February"
month[2]="March"
month[3]="April"
month[4]="May"
month[5]="June"
month[6]="July"
month[7]="August"
month[8]="September"
month[9]="October"
month[10]="November"
month[11]="December"

document.write("<img src=https://www.YOURDOMAIN.com/DIRECTORY-WITH-IMAGES/" + month[d.getMonth()] + ".gif border=0>")

</script>
<!-- END CODE -->
« previous post

next post »

Jen Goode Headshot

Jen is Passionate about Creativity. She is the owner and "doodle in charge" of JGoode Designs, a Denver based design studio. She is an illustrator, mixed media artist and creative lifestyle blogger. Jen has been a creative professional since 1998 but says she's been an artist since she was old enough to eat glue.

Connect:
Facebook iconTwitter iconPinterest IconInstagram IconFeed Icon
Join the FREE Creative Club!

Get tutorials, free file downloads and project ideas right in your email.

1 thought on “Display an image according to the month name using javascript”

Leave a Comment

Featured on:
Brands Jen at 100 Directions has partnered with.
100 Directions is full of tutorials and project ideas to inpsire trying something new and sharing creativity in every direction.
I work with a variety of companies to share ideas and insight about products, services and all kinds of fun, creative things to do.
I stand behind my recommendations and hope you love the things I share as much as I love sharing them with you!

 

Privacy Policy and Disclosures | Work with me

 

100 Directions is a JGoode Designs property. Copyright © 2011-2024 Jen Goode. All Rights Reserved.

100directions.com is a JGoode Designs property. Owned and operated by Jen Goode.