PHP: Automatic Copyright Year Snippet PHP: Automatic Copyright Year Snippet

PHP: Automatic Copyright Year

In website footers, we usually use some kind of copyright notice. Something like: “© 2013”. 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:

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!

    1. 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.

    1. 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 :)

Leave a Reply

Your email address will not be published. Required fields are marked *