Change the heading text, depending on season (spring, summer, autumn, winter)

I am trying to create a ‘Dynamic’ page that will change the heading text of the page / site with each season (based on Australian seasons). eg. When current month is March, my heading need to change to Autumn. Like that depending on the month it need to change to Summer, Winter, Autumn and Spring as well as an added feature for DAY Specific Christmas and New Years.

I found this script but I don’t know how to implement. Could someone please help, because it is not working!!! Thanks

Screenshot|690x331

// Return the southern hemisphere season for a date

// If no date provided, uses current system date
function getSeason(d) {
d = d || new Date();
var mon = d.getMonth() + 1; // Adjust to be indexed from 1
var day = d.getDate();
var seasons = [‘summer’,‘autumn’,‘winter’,‘spring’];

// Do silly seasons here
if (mon == 12) {
if (day >= 13 && day <= 27) {
return ‘xmas’;
}
if (day >= 28 && day <= 31) {
return ‘nye’;
}
}

// If wasn’t a silly season, do others
mon = Math.floor((mon % 12) / 3);
return seasons[mon];
}

console.log('Currently it is ’ + getSeason()); // Currently it is summer

$(document).ready(function(){
  document.body.className = getSeason();
});

@Sam_Hewa I had a look. Now it is working. Add a empty textfield and call it “date-text”.

<script>
	// Return the southern hemisphere season for a date
	// If no date provided, uses current system date
	function getSeason(d) {
		d = d || new Date();
		var mon = d.getMonth() + 1; // Adjust to be indexed from 1
		var day = d.getDate();
		var seasons = ["summer","autumn","winter","spring"];
	
	// Do silly seasons here
	if (mon == 12) {
		if (day >= 13 && day <= 27) {
		return "xmas";
		}
		if (day >= 28 && day <= 31) {
		return "nye";
		}
	}
	
	// If wasn’t a silly season, do others
		mon = Math.floor((mon % 12) / 3);
	return seasons[mon];
	}
		
	$(document).ready(function(){
   $(".date-text").text(getSeason());
	});
</script>

Add the script here:
image

1 Like

Matthias, thanks for this :pray:t3: it’s working now

1 Like