Many times you will come across websites that either have an outdated copyright date or only have one and that really doesn’t tell you how long the site has been functioning.
There is a great solution to this in WordPress however, which automatically updates your copyright date as the years go by.
1) Open your theme’s functions.php file and add the following code:
function comicpress_copyright() {
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
WHERE
post_status = 'publish'
");
$output = '';
if($copyright_dates) {
$copyright = "© " . $copyright_dates[0]->firstdate;
if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
$copyright .= '-' . $copyright_dates[0]->lastdate;
}
$output = $copyright;
}
return $output;
}
2) Open up your theme’s footer.php and add the following code where you would like the copyright date to appear:
<?php echo comicpress_copyright(); ?>
3) You should now see the date display like:
© 2011 – 2012