In website footers, we usually use some kind of copyright notice. Something like: “© 2013 NicoleJeanette.me”. In some cases, it may be tedious or we may forget to update this information, especially when updating website designs. The following snippets will help you have a more automatic function of displaying the year.
Add the snippets to the file where you have your copyright notice, it’s usually in footer.php.
If you want to show the current year only:
© <?php echo date("Y") ?>
// This would look like: © 2021
If you want to show the starting year to the current year:
© 2010 - <?php echo date("Y") ?>
// This would look like: © 2010 - 2021
There’s a function (that validates the information) that you can use to achieve the same information above:
<?php
function CopyrightInfo($year = "default") {
if (intval($year) == "default") {
$year = date("Y");
}
if (intval($year) == date("Y")) {
echo intval($year);
}
if (intval($year) < date("Y")) {
echo intval($year) . " - " . date("Y");
}
if (intval($year) > date("Y")) {
echo date("Y");
}
}
?>
Using the function:
<?php CopyrightInfo(); ?>
It would display as: © 2021.
<?php CopyrightInfo("2010"); ?>
It would display as: © 2010 – 2021
Hope these snippets are useful, if you have questions, don’t hesitate to leave a comment or contact me and I’ll get back to you as soon as I can!
I’ve always meant to do this on my blogs and then always end up forgetting when I actually code the layouts. Then I’m too lazy to go back in and fix it…
Yeah, it happens to me sometimes. Now, one of the first things I code on new themes is the copyright notice because if I don’t I’ll probably forget to add it after the theme is done.
You make this look so easy, but when I think of doing this kind of stuff myself, I freak out. Thanks for the easy to follow tutorials that you post.
You’re welcome! I’m glad you liked it, I never know if they’re clear enough for people to understand. Feel free to contact me if you have any questions Breia :)
Code is so pretty! I’m with Breia, this is way over my head…. for now! I’ll just have to use you as my inspiration :D