Automatically Change The Copyright Year In WordPress
A common question for website owners is “How do I automatically change the copyright year in WordPress?”
Most WordPress themes have a place in the footer for copyright information or site credits.
Sometimes this is in the footer.php
file, sometimes it’s not. It depends on the theme.
I’d like to show you not only how to change the copyright year automatically, but also how to change all types of dates in WordPress.
How WordPress Uses Dates and Times
WordPress core, themes, and plugins use PHP as a server-side programming language. What’s important to know is that WordPress uses PHP conventions for dates and times, and it uses the time from the server it is running on.
PHP has a function called date()
. What the date
function returns is the current date or time, as represented by certain letter symbols. Here is a chart of the more commonly used PHP date and time symbols.
Character | Description | Example Output |
---|---|---|
Y | Numeric 4-digit year | Ex: 2012, 2015 |
y | Numeric 2-digit year | Ex: 01, 16 |
F | Full text of the current month | January—December |
m | Number of current month, with leading zeros | 01—12 |
n | Number of current month, no leading zeros | 1—12 |
M | Three letters of current month | Jan—Dec |
l | Current day, full name (lowercase “L”) | Sunday—Saturday |
D | Current day, three letters | Mon—Sun |
d | Day of the month, with leading zeroes | 01—31 |
j | Day of the month, no leading zeroes | 1—31 |
S | English suffix for day of the week | st, nd, rd, th (1st, 2nd, 3rd, 4th, etc.) |
z | Numeric day of the year (starts with 0) | 0 through 365 |
H | Hour, 24 hour, with leading zeroes | 00 — 23 |
G | Hour, 24 hour, no leading zeroes | 0 — 23 |
h | Hour, 12 hour, with leading zeroes | 01 — 12 |
g | Hour, 12 hour, no leading zeroes | 1 — 12 |
i | Minutes, with leading zeroes | 00 — 59 |
s | Seconds, with leading zeroes | 00 — 59 |
a | Time of day, lowercase | am, pm |
A | Time of day, uppercase | AM, PM |
T | Timezone abbreviation | EST, PST, MDT, etc. |
e | Timezone identifier | UTC, GMT, etc. |
We’ll come back to this chart in future posts, but for now, let’s output the year to our WordPress footer
Automatically Change Copyright Year In WordPress Footer
To output your copyright year to the screen, we use a PHP language construct, called echo
.
In simple terms, echo
tells PHP to output whatever follows to the screen.
Here’s how we would output a copyright notice in WordPress that automatically updates the year whenever the calendar changes. Notice that we wrap PHP in it’s own opening and closing tags.
/**
* ©
is the HTML code for the copyright symbol. You can also use ©
;
**/
<p>Copyright ©
Your Website <?php echo date("Y"); ?>. All Rights Reserved.</p>
WordPress has several built-in functions of it’s own for dealing with times and dates, which we’ll talk about in coming articles.
This can also be easily done by a simple plugin like this: https://wordpress.org/plugins/automatic-copyrights-shortcode/ to dynamically update the year of copyright.
Some WordPress themes are constructed to allow custom text in lower left or right hand side of the footer, or at the bottom of the footer. This would work for situations like that.
Most people who are developing a theme will want the copyright year to update programmatically, so they don’t have to remember.
They could use
echo do_shortcode()
with this plugin, as well.