Tuesday, December 1, 2020
Home Blogging How to Add a Dynamic Copyright Date in WordPress Footer

How to Add a Dynamic Copyright Date in WordPress Footer

Typically you will notice a web site that has an outdated copyright date which is fairly annoying. There are additionally websites that solely present the present yr for his or her copyright date which is much more annoying since you gained’t know the way previous the positioning is. There’s a easy PHP resolution to this that almost all builders would know, however there’s a extra elegant method that we’ll present you. On this article, we’ll share a perform that may mechanically generate a copyright date primarily based on the printed date of your oldest and latest submit.

Easy PHP Resolution for Dynamic Copyright Date

You’ll paste one thing like this in your theme’s capabilities.php file

1
&copy; 2009 – <?php echo date('Y'); ?> YourSite.com

The issue with this concern is that you would need to add this as soon as your website is a minimum of one yr previous.

Elegant WordPress Resolution for Dynamic Copyright Date

Whereas browsing the online, we noticed a extra elegant resolution prompt by @frumph of CompicPress Theme. They’re utilizing this perform on their glorious ComicPress theme. This perform will generate a dynamic copyright date primarily based on the printed date of your oldest submit and your latest submit. If it’s the first yr of your website, then this perform will solely show the present yr.

You May Also Like : How to Create a WordPress Plugins

To implement this dynamic copyright date in your WordPress footer, open your theme’s capabilities.php file and add the next code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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 = "&copy; " . $copyright_dates[0]->firstdate;
if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
$copyright .= '-' . $copyright_dates[0]->lastdate;
}
$output = $copyright;
}
return $output;
}

Then open your theme’s footer.php file and add the next code the place you wish to show the date:

1
<?php echo comicpress_copyright(); ?>

This perform will add the next textual content:

© 2009 – 2016

Don’t hold your copyright dates outdated. Reap the benefits of this system in your present and future WordPress websites.

If you liked this article, make sure to hit the bell for getting our latest updates and share this article with your friends in every social media platforms.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Social Warfare Review: Explode your Social Shares

Everybody is aware of that having social media sharing buttons is important for each weblog within the Blogosphere. Why? Well, social media sharing buttons assist us...

10 Android Money Earning Apps & Cash For Real

You pay for some app’s within the app retailer otherwise you purchase in-app purchases. But do you know you would earn money by utilizing apps...

Cuelinks Review – Easy Affiliate Marketing for Indian Bloggers

Are you an Indian blogger with tons of Indian visitors? Want to earn cash out of your weblog past AdSense? If your reply is Yes, right...

How to Signup for Godaddy Affiliate Program & Start Making Money

GoDaddy is likely one of the well-liked model names out there of area and web-hosting. They are well-liked for a numerous cause, and so they...

Recent Comments