JavaScript: automatically update the year in your footer
William Hammond provides us with a very handy code addition to automatically change the year accompanying your footer copyright.
Forgetting to update trifling elements of a web page is something that I am guilty of, as I am sure a lot of you are as well. But worry not, as I have a very quick and easy trick to alleviate at least some of that aggravation!
Its purpose is to automatically update the year in your footer; although it seems pedantic to automate such a minor detail, having to manually update every page on your website each subsequent year proves to be an exhausting task - especially for larger websites.
So without further adieu, here is the code to inject:
HTML
<p>
© <!--copyright symbol-->
<span id="currentYear">x</span> <!--current year-->
<a href="https://www.yourwebsite.co.uk" target="_blank"> <!--link to your website-->
Website by you.</a>
</p>
JavaScript
<script>
var currentYear = new Date().getFullYear(); //variable containing current year
document.getElementById("currentYear").innerHTML = currentYear; //set specified HTML element to currentYear variable
</script>
You can either add the JavaScript to the head code injection area, or below the HTML within a code block (suitable for websites on the personal plan).
You can change the HTML code to tailor it to your own website, but do not modify the "<span id="currentYear">x</span>" line of the code, as this is what JavaScript uses to update each year.
I hope you have found this useful!
Will :)