Introduction
Are you looking for a simple but effective way to add a dynamic copyright date to your WordPress footer? That means your site automatically creates the copyright date range from the published dates of your oldest and newest posts. If you want to do that, let us help you with today’s instructions. Now, let’s check it out!
How to add a dynamic copyright date to the footer
PHP method
In order to use this method, your site needs to be at least one year old. Now, all you need to do is open the footer.php file, then add the following code on the line where you want to display the copyright:
<p>© 2020 – <?php echo date('Y'); ?> YourSite.com</p>
However, there is a downside to using this solution: it cannot automatically fetch the start date of your site.
Elegant WordPress solution
If you don’t want to use the method above or your website has only been launched recently, let’s try the solution below. For this method, add the following code to the theme’s functions.php file or a site-specific plugin:
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;
}
This code creates a dynamic copyright date from the published dates of both the oldest and the newest posts. If it is the site’s first year, it will simply show the current year.
After adding the code above, let’s go to the theme’s footer.php file. Then, simply add the following code where you want to display the date:
<?php echo comicpress_copyright(); ?>
Now, you will see text like this:
© 2009 – 2021
Conclusion
All in all, with the two methods we have introduced, we hope that you can easily keep your copyright dates updated. If you think this blog is useful, don’t hesitate to share it with your friends. Furthermore, don’t forget to visit our site when you have free time because we provide many Free WordPress Themes.



