How to Make the Copyright Year Change Automatically
This simple trick is great for preventing your website from looking out of date
1 month ago | by Charlie Cooper
One of the biggest telltale signs of an outdated website is a really old copyright year. Imagine going onto a website and seeing © Copyright 2011 at the bottom. It’s a bit of a giveaway!
With this simple trick we can stop that from happening using a simple PHP function that gets the current year. Let’s jump right in.
To keep this simple and easy to follow we’re going to make a new shortcode in WordPress. Anyone can do it!
1.Open the Theme File Editor
First, you’re going to need access to functions.php in your root of your theme. You can access this by going to ‘Appearance > Theme File Editor’ from your WordPress backend.
2.Open functions.php
Once on the theme file editor page, look on the right of the page where all the file names are and find functions.php. Click it to view the contents.
3.Paste in the shortcode function
Now scroll right to the bottom of the file and if you can see ?>, simply remove it.
If it’s not there you’re ready to continue. Now paste in the code below and hit ‘Update File’.
add_shortcode( 'current-year', 'get_current_year'); function get_current_year() { return date("Y"); }
We’ve now added a shortcode to your website. This means that when you type [current-year] it will output 2023.
Use the shortcode in your footer
Most of the time, you’ll find the copyright text for your theme somewhere in the theme settings or occasionally it’s a widget.
All you need to do is replace the year with the shortcode we’ve just created and WordPress will do the rest.
For example, when you find the text for the copyright and it says ‘Copyright 2023‘ you’ll change that to ‘Copyright [current-year]’.
All done! You should now see the current year in your footer, and when next year comes around, it will change automatically.
Note: If you’re editing a PHP template such as footer.php directly you’ll need to use this code:
echo do_shortcode('[current-year]');