Posts Tagged ‘PHP’

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: ,