Automatically update the copyright on your website with PHP

Posted on: March 15th, 2010 | Category: code

This is one of those little things you always forget, probably because it’s so small and insignificant.

Did you ever have a client call or e-mail you with the question to update the copyright on the website you created for them last year? I know I have had those questions from clients (rightly so).

With this little code snippet you’ll never have to worry about it again.

Place this somewhere in your functions.php (or whatever you named it):

function printCopyright($startyear) {
	$currentyear = date(Y);
	if ($startyear == $currentyear) {
		echo 'Copyright © '. $startyear;
	else {
		echo 'Copyright © '. $startyear .' - '. $currentyear;

Once that is in your functions.php you can just use this: <?php printCopyright(2010); ?> in your template where you want your copyright to be printed. It takes one parameter, the year you want your copyright to start or has started.

If the current year is also the year your copyright started, then it will return “Copyright © 2010” and if your copyright started earlier (let’s say in 2007), then it will return “Copyright © 2007 – 2010”.

Tags: ,


Leave your own comment »

  1. Mathias Bynens

    I think that should be date('Y') instead of just date(Y) ;)

    Posted on: 16/3/2011 at 14:30 - #

  2. math games

    Thank you for the source code

    Posted on: 20/7/2019 at 20:59 - #

Leave a Reply

Keep it polite and on-topic please.

The Fine print™: By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution.
Your email is never published nor shared. Required fields are marked *