Here, we are going to explain how to update copyright notice automatically in Wordpress.
If you ever noticed that most of the websites forgot updating the year in the copyright notice which is a very little and easy task. The one way you can update your copyright by using this trick, it automatically generates the copyright date based on the year.
We are going to write a code for this trick here and will paste the following code into Theme's functions (functions.php) file.
function wpb_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;
}
After adding this code in functions, you will need to open footer.php file and add the following code below wherever you want to display. It will updating dynamically on your website.
//echo wpb_copyright(); add the following code wherever you want the copyright information to be displayed
we added the copyright code in the footer.php file so it would be displayed at the bottom of the website.
Enjoy!!
Automatically Update Your Copyright Notice in Wordpress
Here, we are going to explain how to update copyright notice automatically in Wordpress. If you ever noticed that most of the websites forgo...