Australia's Leading Digital Marketing Experts. T. 1300 235 433  |  Aggregation Enquires Welcome

Add Automatic Copyright Year With PHP

Virtually every website has a copyright icon and string indicating the years of website operation. It's surprising how many sites still use a single static date that doesn't reflect the years the site has existed. The following function is designed to return the date of website origin through to the current year.

1
<?php 
2
/*
3
 Add Automatic Copyright Year With PHP
4
 http://www.beliefmedia.com/code/php-snippets/copyright-year
5
*/
6
 
7
function bm_copyright($year = '') {
8
  if ($year == '') return '© ' . date('Y');
9
 return ( $year == date('Y') ) ? '© ' . $year : '© ' . $year . ' - ' . date('Y');
10
}
11
 
12
/* Usage */
13
echo bm_copyright('2012');

Returns: © 2012 - 2017.

Of course, you can return the current year with just the following:

1
<?php 
2
echo '© ' . date('Y');

The from and to date can be returned with the following (the only difference to the function above is that it doesn't correct if the start and current year are the same).

1
<?php 
2
echo '© 2012 - ' . date('Y');

Like this article?

Share on facebook
Share on Facebook
Share on twitter
Share on Twitter
Share on linkedin
Share on Linkdin
Share on pinterest
Share on Pinterest

Leave a comment