Generating a Dynamic Copyright Notice in WordPress
Copyright notices are located in the footer of almost every website on the Internet and for good reason, it’s part of what protects us from content thieves or at least in theory but most of our copyright notices are outdated or hand coded, even in WordPress so how do we get around this?
The Current Year
My first solution was to place a small piece of PHP code in the footer of my WordPress file so that it always showed the current year, like so:
Copyright <?php echo date(“Y”);?> Christopher Ross.
Which resulting in:
Copyright 2009 Christopher Ross.
An Earlier Year to The Current Year
That system worked fine but was technically wrong since many of my posts predate 2009, which led me to my second solution of simply posting an earlier date in front of the PHP code like so:
Copyright 2005-<?php echo date(“Y”);?> Christopher Ross.
Still, technically wrong since I had no idea what the earliest post in my blog was and I’m too lazy to search through all the posts to find out. Which led me to the desire a script which would automatically find the first occurrence of a post in my blog and post the results as a copyright statement.
Automating the Copyright notice
To automate the copyright notice, first I needed to establish the first post as well as the last. The following code will accomplish that task:
function copyright() {
global $wpdb;
$posts = $wpdb->get_results(“SELECT YEAR(post_date_gmt) AS year FROM $wpdb->posts WHERE post_date_gmt > 1970 ORDER BY post_date_gmt ASC”);
$last = $posts[count($posts)-1]->year;
$first = $posts[0]->year;
$c = __(‘Copyright (©) ‘, ‘inove’) . $first;
if($first != $last) {
$c .= ‘-’. $last;
}
return $c;
}
Simply placing the function in your functions.php file will allow you to insert the code <?php echo copyright();?> into your footer, resulting in a fully automated copyright notice as you can see on the footer of my website.
For those users who prefer to use a plugin, I’ve uploaded a WordPress plugin version of the copyright tool as well.






[...] the original post: Generating a Dynamic Copyright Notice in WordPress :: Christopher Ross This entry was posted on Wednesday, January 21st, 2009 and is filed under Wordpress Hosting. You [...]
hi. Thanks for plugin
perfect.
Regards
Thanx for the plugin. There a plugin for every small things nowadays :d ..
Dave’s last blog post..Make your Wordpress Blog Secure/ HackerSafe