Copyright Up To Date (The Automate Way)

eligarlo

Eliahu Garcia Lozano

Posted on October 6, 2020

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>
Enter fullscreen mode Exit fullscreen mode

And then, our javascript will look like this:

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

copyright.innerHTML = new Date().getFullYear()
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode
const copyright = document.querySelector('#copyright')

copyright.innerHTML += new Date().getFullYear()
Enter fullscreen mode Exit fullscreen mode

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

💖 💪 🙅 🚩
eligarlo
Eliahu Garcia Lozano

Posted on October 6, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related