Don't forget to include a self-updating copyright notice with this 5-minute tutorial.

Have you ever come across active websites with obsolte copyright notice? Ouch. Sometimes a minor oversight can get you into legal troubles. Hence this mini-tutorial will help you auto-update copyright to your WordPress website.

This tutorial is also great for aspiring WordPress developers wrestling with the unforgiving nature of the PHP language. I know because I’ve been there. Learning how to auto-update copyright is nothing fancy, but let’s take baby steps towards PHP mastery, shall we?

Without further ado, let’s dive in the exercise.

Step 1: Set up the variables

First, open the footer.php file, which is usually available from wp-content/themes/your theme’s name/footer.

In the footer.php file, set up a variable which will the be start year inside a PHP statement. This is the year that you website went live for the first time. Mine was born in 2018, so at the time of this writing, it is still an infant.

$startYear = 2018;


Next, we need a variable for this year. We’ll call that variable thisYear and use the date function and uppercase Y gives you the current year. This is pure PHP, and you can reference the Date and Time format directly from the PHP manual.

$thisYear = date('Y');

Then we need to find out if the current year is greater than the first year. That means we’ll be using an if statement.

if ($thisYear > $startYear) {
$copyright = "startYear–$thisYear"
} else {
$copyright = $startYear;
}

Let me explain what we’ve done. If the current year is greater that the start year, the copyright notice will be displayed as follows: © 2018-2019. An ampersand followed by ndash is HTML Unicode for an en dash.

Alternatively, if one year hasn’t passed since the start year, our copyright will be © 2018.

Your code block should look like this:

Auto-Update Copyright—Set Up Variables

Step 2a: Auto-update copyright

Now, find the part in your footer.php file that outputs all the footer content and add the markups for the copyright.

<p id="copyright" role="contentinfo">© Komono Design</p>

insert this statement after the copyright symbol and before your business name:

<?php echo $copyright; ?>

The echo statement simply outputs data to the screen. Nothing more, nothing less.

Auto-Update Copyright—Echo Statement

Step 2b: Another year format

Wait, what if you want just two digits at the end, like © 2018-19. I think this one looks more pleasant on the eye. To do that, simply change the date function to lowercase y.

$thisYear = date('y');

Below is a dummy site I created for this tutorial, but you get the idea. When the year passes, the copyright notice will self-update. One less thing to add to your plate, right?

That’s an easy peasy exercise, right? The cool thing about auto-updating copyright is that you can totally set it and forget it. With the copyright taken care of, now you can go build your own empire.

Stay inspired. Subscribe to my infrequent newsletters.(You won't regret it).

Leave a Reply

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