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

User avatar
Mitch
Posts: 38
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());
</script>
Result:
2018
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.
Result:
© 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:
2018
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


Return to “WEBSITE AND WEB DESIGN”

Links

In total there are 6 users online :: 0 registered, 0 hidden and 6 guests
Registered users: No registered users
Most users ever online was 156 on Sun Jun 17, 2018 7:42 am
Total posts 449
Total topics 328
Total members 62
Our newest member anonymous-kali
No birthdays today