Thursday, November 28, 2013

Dynamic Copyright Date in WordPress Footer

Often you will come across sites with outdated copyright dates. Some sites show the current year as their copyright date. Both of these are annoying, and it shows that the site designer was lazy. In order to give your users a little background info about your site, you should display the copyright date as such: © 2006 – 2010. We can do this by simply pasting 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;


Once you add this function, then open your footer.php file and add the following code wherever you like to display the dynamic copyright date:


<?php echo comicpress_copyright(); ?>



Dynamic Copyright Date in WordPress Footer

No comments:

Post a Comment

Please mention your comments.......