Let your footer update itself!

blog post cover image Let your footer update itself!

Published December 31, 2022

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

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>
<script>
  const currentYear = new Date().getFullYear();
  document.getElementById("footer-copyright")
    .innerHTML = `Copyright © Your Name ${currentYear}`;
</script>

Happy Coding! ✌️