How to Auto Update Copyright Year in a Website Dynamically (2019)

User avatar
Posts: 53
Joined: Mon Jan 30, 2017 4:58 am

How to Auto Update Copyright Year in a Website Dynamically (2019)

Thu Aug 16, 2018 11:04 am

The Copyright information on a website provides useful information about copyright ownership on the website content. It establishes the creator of that content and also the year the content was originally created. The Website copyright protects the owner‘s rights to the content, logos, images on the website.

The Copyright can be a single year which is the year the site was created. A range of years specifies the year of publishing through the year the content was last revised. If your website has been up for more than a year then it is advisable to show the date range instead of the current year.

So, Here is the code for you:

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.

Code: Select all

<script type="text/javascript">
  document.write(new Date().getFullYear());
If you want a bit more information, here's a snippet you can customize:

Code: Select all

&copy; 2010<script>new Date().getFullYear()>2010&&document.write("-"+new Date().getFullYear());</script>, Company.
© 2010-2018, 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.
You can even install the Node package 'rainge' for having a truly automated way to keep your date stamps updated – you just set the year once, and rainge does the rest.

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:

Code: Select all

<?php echo date("Y"); ?>
This will just give you:
Or if you want more detail in your footer, use something like this:

Code: Select all

&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-2018 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 2018, you still see 2017 here.

Hope this will help you guys now! My friend asked me yesterday if I could post something about this so here it is for you my dear. Thanks



In total there are 3 users online :: 0 registered, 0 hidden and 3 guests
Registered users: No registered users
Most users ever online was 33 on Sat Mar 09, 2019 8:21 pm
Total posts 489
Total topics 371
Total members 70
Our newest member Mirasoida
No birthdays today