WordPress Tip: Automatic and Dynamic Copyright Code

January 18, 2009 – 9:39 am

copyquestionYou’ll never have to manually update your copyright information again. That’s an easy promise to make with the easy code provided below. Simply input your initial copyright year, i.e. your first year of publication, and the code keeps up with the rest.

There are numerous ways to display a copyright notice on your website, and numerous scripts available to dynamically show your current copyright year (this year). The following code does both, but also shows your copyright year range, say, from 2004 to 2009. So, you can display:

Copyright © 2004 vs. Copyright © 2004-2009

If you are in your first year of copyright, the code shows only your current year.

Let’s begin

Open the file functions.php located in your theme folder – wp-content / themes / yourtheme. If there is no functions.php, don’t worry. Just create a new file with this name in your theme folder. Add the code below to the file somewhere between the <?php and ?> lines. If you had to create the functions.php file, simply add <?php to the beginning of the file and ?> to the end (note! do not add a line break at the end of the file).


function copyright($firstyear,$owner=0) {
$cyear = ($firstyear) != ($current = date("Y")) ? "$firstyear - $current" : $current;
$owner = $owner ? " ".$owner : " ".get_bloginfo('name');
$copyright = "Copyright © ".$cyear.$owner.".";
echo $copyright;
}

Wherever you would like your copyright information to show, add the code below:


copyright("2008");

This will show Copyright © 2008 – 2009 YourSiteName. Change 2008 to your first year of publication. Place the code between <?php and ?> tags if needed.

Specify copyright owner

If you would like to use copyright owner text that is different from your site name, specify the owner using this code instead:


copyright("2008","MyNameHere");

This will show Copyright © 2008 – 2009 MyNameHere. Change 2008 to your first year of publication. Change MyNameHere to any text you’d like. Place the code between <?php and ?> tags if needed.

Code inspiration from Click to visit this external linkDZone Snippets.

How’d it work for you? Let me know!

icon

0 Comments

    Add a Comment