Like the blog? Get the book »

How to Display a Copyright as a Range of Dates

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 @
function copyrightDate() {
	global $wpdb;
	$copyright_dates = $wpdb->get_results("
			YEAR(min(post_date_gmt)) AS firstdate, 
			YEAR(max(post_date_gmt)) AS lastdate 
	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.


12 responses

  1. Interesting tip, but does seem sight overkill for just displaying the copyright date!

    • It all depends on usage and context, I suppose. Nothing critical, certainly, but a nice feature that could enhance a publicly released theme.

  2. Pieter de Jong

    What’s wrong with just the current year?

  3. Nice idea pulling the dates from the database, why didn’t I think of that? :P

    *goes to implement on his site*

  4. 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.

  5. Ian Storm Taylor

    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.

  6. 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!

    • Not sure what you mean here. There is really only one function that we are sharing here, copyrightDate, which shows a range of dates in a copyright statement.

      • This “range of dates in a copyright statement” can be simply achieved by the second piece of code you gave above (combine of plain text with php date function). So what’s the benefit of that function?

        I’m sorry! I can’t speak english very well.

      • The idea is that the function would enable your theme to display a range of dates automatically. There are many reasons why this may be useful, such as making it easy for theme developers to include a range of dates for their users. It simply eliminates a step for users and simplifies the implementation process. Does that make sense, or have I completely lost my mind?

  7. 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. :)

Comments are closed for this post. Contact us with any critical information.
© 2009–2024 Digging Into WordPress Powered by WordPress Monzilla Media shapeSpace