The Problem: Every year the footer of your personal or company website will need to be updated. It would be a waste of your time and you would risk breaking your code if you needed to update every single webpage to type “2020” in the footer of the page. This should be automated.
The Solution: Use JavaScript to get the date, set it as a variable, and display the result in the footer of the page.
<script type="text/javascript"> //Declares the JavaScript
let d = new Date(); // Creates a variable and calls Date Object
document.write(d.getFullYear()); // Calls getFullYear method on variable d(new Date() Object) and displays year
</script> // Closing bracket
The code above can be copied and pasted into the footer of your website pages. If you have a couple of static pages, it isn’t a big deal to edit each page. In my case, I added the code to the footer.php file for my custom WordPress theme. WordPress automatically appends the footer.php to every new post or page that I create. Now a user will always see a dynamically generated date at the bottom of the page.