was successfully added to your cart.

It’s 2016. Update Your Footer.

By January 2, 2016Coding

Are you tired of changing your website’s footer year after year? 2016 is a year of working smarter, not harder. Check out this snippet of code to make your website’s footer dynamic so you don’t have to keep changing it. Done!

From: http://updateyourfooter.com/

JavaScript Snippets

This is pure JavaScript, meaning it will refresh the year browser-side, depending on the user’s time settings. Just copy the below snippet and paste it where you want your dynamic text in the footer to appear.

<script type="text/javascript">
  document.write(new Date().getFullYear());
</script>

This will just give you:

2016

If you want a bit more information, here’s a snippet you can customize:

&copy; 2010<script>new Date().getFullYear()>2010&&document.write("-"+new Date().getFullYear());</script>, Company.

Which will give you:

© 2010-2016, Company.

Because JavaScript works on the client (the user’s browser, that is), it is dependent on the user’s settings. In most cases it will likely be what you’d expect. Here’s more info on the JavaScript Date Object.

PHP Snippets

Here’s the same in PHP so you can do this server-side. Use WordPress? Find the ‘footer.php’ in your Editor and add this there (here are videos to help you with that). The below snippet will just show the current year:

<?php echo date("Y"); ?>

This will just give you:

2016

Or if you want more detail in your footer, use something like this:

&copy; <?php 
  $fromYear = 2008; 
  $thisYear = (int)date('Y'); 
  echo $fromYear . (($fromYear != $thisYear) ? '-' . $thisYear : '');?> Company.

Or you can go for ($fromYear < $thisYear) in the above to account for any time reversal (or a confused server, more likely). But either will give you:

© 2008-2016 Company.

Since PHP works on the server, it will display the year the server is currently in. Thus, if you look at this from Europe in the wee hours of 2016, you still see 2015 here.

 

×