Get the Right Copyright Dates in Your Blog Footer

A tip for self-hosted WordPress users.

Contrary to popular belief, most blogs are copyrighted. As a result, most blog themes include a copyright notice in the footer.

How the copyright notice is entered into the theme determines how it appears:

  • If entered as plain text, it appears as a static date or range of dates — whatever you entered. This means that each new year — right about now — you need to change the static text to include the current year.
  • If entered using tags that pull the most recent date’s year from your WordPress blog — or just use the current year — a range of dates may not appear at all. Instead, there will be just one date. That’s better, but not exactly accurate.
  • If entered using PHP tags that get the first and last years of blog posts and put them in a range — you never have to modify the footer to change the dates and they always include the entire range of post years. This is the best solution and it isn’t difficult to do.

To automatically display a range of dates from the year of your first post to your most recent post in a copyright notice, just edit the code in the footer to remove your current copyright notice code and replace it with this:


<?php
     global $wpdb;
     $post_datetimes = $wpdb->get_results("SELECT YEAR(post_date_gmt) AS year FROM $wpdb->posts WHERE post_date_gmt > 1970 ORDER BY post_date_gmt ASC");
     $firstpost_year = $post_datetimes[0]->year;
     $lastpost_year = $post_datetimes[count($post_datetimes)-1]->year;

     $copyright = __('Copyright &copy; ') . $firstpost_year;
     if($firstpost_year != $lastpost_year) {
          $copyright .= '-'. $lastpost_year;
     }

     echo $copyright;
?>
<?php bloginfo('name'); ?>

The result, on this blog, would be something like:

Copyright © 2004-2009 Maria's Guides

If you prefer to have your name appear instead of the name of your blog, replace the last line with your name. That’s what I do.

Lynda.comLearn More

Learn more about working with a self-hosted WordPress 2.7 installation — or WordPress.com. Check out my WordPress courses on Lynda.com.