How to Add a Dynamic Copyright Date in WordPress Footer263

How-to-Add-a-Dynamic-Copyright-Date-in-WordPress-Footer
Author: InfoBeep - December 5, 2017 | subject to copyright

Adding a copyright date makes your site look professional. But, if there is something wrong, it may annoy your reader. In this article, we will guide you to add dynamic copyright date in WordPress Footer of your site.

Procedure

Now, to begin the process add the code below in your functions.php file:

functioncomicpress_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;

}


Now open your theme’s footer.php file and paste the code below:

<?php echocomicpress_copyright(); ?>

You are done, now you should see copyright date ranging from your beginning postdate to most recent postdate. Meaning, if you have your blog post starting from 2009 and you have also posted your post in 2017 it will show “© 2009 – 2017”.