Copyright Up To Date (The Automate Way)

Copyright Up To Date (The Automate Way)

Let's be honest, outdated copyright disclaimers on a website looks bad. Looks like the website it's unmaintained on many levels. On the other hand, you don't want to manually update it every 1st of January on every website you own right? Let me help you automate this task with 2 lines of code. If you want to know more about the importance of updating your copyright dates I found this post with a more in-depth explanation.

First, let's create a basic HTML template where we will have our copyright disclaimer at the footer:

<body>
  <header>Lorem ipsum dolor sit</header>

  <main>Lorem ipsum dolor sit amet consectetur adipisicing elit.</main>

  <footer>Copyright © <span id="copyright"></span>, My Company Name</footer>

  <script src="app.js"></script>
</body>

And then, our javascript will look like this:

const copyright = document.querySelector('#copyright')

copyright.innerHTML = new Date().getFullYear()

That's it, you are cover now. 😎

Bonus tip:💡

In case you need a range of years instead of a single year in your copyright disclaimer, you can easily tweak the above code.

<footer>Copyright © <span id="copyright">2010 - </span>, My Company Name</footer>
const copyright = document.querySelector('#copyright')

copyright.innerHTML += new Date().getFullYear()

Thank you for reading, if you like my content, you can always find me on Twitter @eligarlo.