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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

The Work
Follow WP-DD.com
Wordpress Web Hosting