Forgot to update the year in the footer again? Fix it once and for all with this simple javascript snippet - ByteScout
  • Home
  • /
  • Blog
  • /
  • Forgot to update the year in the footer again? Fix it once and for all with this simple javascript snippet

Forgot to update the year in the footer again? Fix it once and for all with this simple javascript snippet

This article was updated on January 8, 2021. Initially published on January 14, 2019

updating year to 2021 update in the footer

It is this time of the year. I mean it is  2020 2021 already but many websites still have their footers showing previous year, like this “MySiteName.com (c) 2018-2020“. Someone was too busy and forgot to change the footer for 2021.

Thanks to the Gods of Javascript and browsers, you can easily fix it with just one line of Javascript code once and for all. your website visitors won’t think “gosh, are these guys still in business in 2020?”

If you use WordPress:

  1. Go to yourwebsite.com/wp-admin to open admin panel
  2. Find your theme name in the left menu (Avada, Jupiter or any other that you have on your website)
  3. Open it and find “Footer” option
  4. Footer content editor will open, switch to Text mode

If you use another website management system then simply find a place in the code which is used for a footer.

Your current footer probably looks like this:

© Copyright 2010-2020 MyWebSite.com — All Rights Reserved

Replace it with the following html and a small JavaScript code where 2020 is replaced with JavaScript snippet automatically showing the current year.

© Copyright 2010-
<span id='footer-copyright'></span>
<script>
document.getElementById('footer-copyright').
appendChild(document.createTextNode(
new Date().getFullYear()));
</script>
 MyWebSite.com — All Rights Reserved

Save your footer and open your website. You will see that now it automatically shows the current year (and will adjust it automatically):

© Copyright 2010-2021 MyWebSite.com — All Rights Reserved

How it works?

Every time a visitor opens your website in a browser, this JavaScript snippet reads a current year from the browser and shows it to a viewer! You may relax next January because the copyright year in the footer will change for visitors to your website automatically.

Troubleshooting:

I’m using WordPress and I see some strange symbols instead of the year.

Solution:

Probably you forgot to switch to Text mode when you were editing Footer. Try again and update the footer in Text mode, save and check again.

   

About the Author

ByteScout Team ByteScout Team of Writers ByteScout has a team of professional writers proficient in different technical topics. We select the best writers to cover interesting and trending topics for our readers. We love developers and we hope our articles help you learn about programming and programmers.  
prev
next