Dynamic Copyright Date in WordPress Footer
Sometimes you will will see various websites with outdated copyright dates. Some of the websites show the current year as their copyright date. This is not a very good sign for a website.To give your users a little background information about your website, you should display the copyright date like: © 2010 – 2012. You can do this by just pasting the following code:
function updated_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;
}
Once you haveadd this function, now open your footer.php file in theme folder add the following code in the footer or wherever you want to display the dynamic copyright date:
<?php echo updated_copyright(); ?>
This function looks for the date of your first post, and the date of your last post. It then echos the years wherever you call the function.
Sometimes you will will see various websites with outdated copyright dates. Some of the websites show the current year as their copyright date. This is not a very good sign for a website.To give your users a little background information about your website, you should display the copyright date like: © 2010 – 2012. You can do this by just pasting the following code:
function updated_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;
}
Once you haveadd this function, now open your footer.php file in theme folder add the following code in the footer or wherever you want to display the dynamic copyright date:
<?php echo updated_copyright(); ?>
This function looks for the date of your first post, and the date of your last post. It then echos the years wherever you call the function.
No comments:
Post a Comment