How to Display a Copyright as a Range of Dates
Technically, your work is protected under copyright “the moment it is created and fixed in a tangible form that it is perceptible either directly or with the aid of a machine or device.” 1 Registration of your copyrighted work is not required2, but you should include a copyright notice on all published works3. So it’s a good idea to display a copyright notice on all of your blog posts and pages.
Displaying a copyright statement in the footer of your web pages is easily done with something like this:
Copyright © <?php echo date('Y'); ?> Digging into WordPress
This code will output the following text:
Copyright © 2009 Digging into WordPress
I think most of us are familiar with this technique, as it would be a total pain to manually update the copyright date on all of your sites every year.
But what if you want to display your site’s copyright statement as a range of dates instead of just the current year? Many sites do this, and I am guessing that they do something like this in their source code:
Copyright © 2008 - <?php echo date('Y'); ?> Digging into WordPress
While this method certainly works, it would be better to automate the process and have the range of dates displayed dynamically. This would be especially helpful for publicly released themes, where you want to minimize the amount of “fiddling” involved with the setup and configuration process.
To display a copyright as a range of dates for your theme, add the following function to your theme’s functions.php
file:
<?php // display range of dates for copyright @ digwp.com
function copyrightDate() {
global $wpdb;
$copyright_dates = $wpdb->get_results("
SELECT
YEAR(min(post_date_gmt)) AS firstdate,
YEAR(max(post_date_gmt)) AS lastdate
FROM
$wpdb->posts
");
if($copyright_dates) {
$copyright = "Copyright © " . $copyright_dates[0]->firstdate;
if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
$copyright .= '-' . $copyright_dates[0]->lastdate;
}
echo $copyright . " " . get_bloginfo('name');
}
}
add_filter('wp_footer', 'copyrightDate');
?>
That’s all there is to it. Nothing else needs to be done in order for this code to output the something similar to the following:
Copyright © 2008-2009 Digging into WordPress
If your site is less than a year old, the function will simply print a single-year copyright date:
Copyright © 2009 Digging into WordPress
By default, this function will display this information wherever the following hook is located in your theme:
<?php wp_footer(); ?>
If this hook is not present, of if you would like to customize the location of the copyright statement, simply call the function anywhere in your theme with the following tag:
<?php copyrightDate(); ?>
Depending on your theme setup, if you call the function directly, you may want to comment out the last line (i.e., add_filter()
) in the function itself to prevent duplicate output.
Notes
- 1 Source: Copyright.gov
- 2 Unless you wish to bring a lawsuit for infringement of a U.S. work.
- 3 Source: Intellectual Property crash course
12 responses
-
Interesting tip, but does seem sight overkill for just displaying the copyright date!
-
What’s wrong with just the current year?
-
Nice idea pulling the dates from the database, why didn’t I think of that? :P
*goes to implement on his site*
-
I have to agree that it is a bit of an overkill. It also doesn’t take into account using WordPress as a non-blog CMS. I think setting your own “start” date for your copyright is the right way to go.
-
Very useful indeed.
I’d only worry about the extra script for something that could be static. But of course, as you said, for theme developers that would be useful.
-
I think i get it wrong. The second piece of code does the job and does not need to be updated. So, what’s the benefit of copyrightDate function against that code?
I should say that copyrightDate function was pretty neat. Thank you!
-
No No! Now I got the idea. This will enable the theme to work on any site. Good for theme developers that publish their theme to community.
Thanks for your patient. :)