Changing your footer’s year is a thing of the past

blog post automatic footer year update
Published:  December 31, 2022

How you can automate updating the year in your footer, only with a few JavaScript lines.

I am still seeing Blogs and Onlineshops with an outdated year in the footer. This looks unprofessional and hurts trusting the website. If someone can’t manage their footer, is it safe to provide my data?

Here is a little JavaScript snippet that you can add in your footer and never have to think of updating it again after the New Year.

Note: There are a few blogs that recommend calling document.write(), this is considered poor practice. Using document.write() would lead to halting the DOM creation and slow down the webpage. Instead you can use a selector and insert the year via innerHTML.

In WordPress the code should be inserted in the footer.php of your child theme right before the closing </body> Tag.

<p id="footer-copyright"></p>
		const currentYear = new Date().getFullYear();
		document.getElementById("footer-copyright").innerHTML = `Copyright © Your Name ${currentYear}`

Leave a comment

Your email address will not be published. Required fields are marked *