Cover Image

Update your Footer

December 31, 2018

Let’s face it. We’ve all run into the issue where we are scrolling through a site and we get to the bottom and notice that the year in the footer has not been updated to the current year. If you happen to be managing that site, you rapidly rush to the computer, open up the source code, search for outdated year, add one to that year, commit and deploy. Phew …glad we caught that before the client!

Ok, maybe we all haven’t been there. Maybe you were smarter than I and you already know that there is a quick and easy solution so that you don’t have to manually repeat this process year after year…

The Solution

The fix is quite easy and I’ve broken it down into JavaScript and PHP, the two main languages I use for projects.

JavaScript

Replace the static year 2018 with new Date().getFullYear()

For example, on this site I do something similar to the following…

const currentYear = new Date().getFullYear()

<p>
  &copy; {currentYear} Chris Baucom.
</p>

You can even simplify it to just the one line…

<p>&copy; {new Date().getFullYear()} Chris Baucom.</p>

PHP

Replace the static year 2018 with <?php echo date("Y"); ?> or if you use Laravel, {{ date('Y') }}

That’s all folks! Happy New Year!!!