Skip links

Automatically Update The Footer Year In Wordpress With This Nifty Code Snippet

How many times have you visited a website and discovered their footer date was outdated? Probably by two, three, years or even more? While it is just a ‘minor’ detail, it can send a wrong message and sometimes you begin if the website owner is even a serious person. If you’re a business owner yourself who keeps forgetting to update the date in the footer when the new year comes around, I understand. Our brains are naturally lazy and wired to forget things like that.

Fortunately, there is a solution to this problem – using a code snippet that outputs a shortcode which automatically updates the year in the footer for you. Here’s how to do it:

If you’re a geek or dev or you know how to get your hands dirty with code:

1. Open the functions.php file of your Wordpress theme from your Wordpress Editor; preferably your child theme to prevent this code from being overwritten when your parent theme updates.

2. Add the following code to the functions.php file:

function current_year_shortcode() {
  return date('Y');
add_shortcode('current_year', 'current_year_shortcode');

3. Save the changes to the functions.php file.

4. The above code will output a shortcode called [current_year] which you can now use in place of the manual date in the footer. Save changes and the current date will appear. When the next calender year comes around, it will automatically update itself!

If you don’t want to get messy with functions.php:

1. Install the Code Snippets plugin from the Wordpress Plugin Repository. This plugin allow you add code to your website safely, without diving into your functions.php file and breaking something. And if there is something wrong with the code, it will not allow the code to run, and then automatically reverse the changes. Pretty nifty tool.

2. Once installed, navigate to the Snippets area that will appear inside Wordpress.

3. Click ‘Add New’ and insert the code provided above in the code area of Code Snippets.

4. Enter a title (for filing purposes), choose ‘allow the snippet’ to run everywhere and hit ‘Save Changes’. The code should now be active. One final step though.

5. Copy the shortcode: [current_year] and replace where you have the manual date in your footer, for example: © 2022 Abacus Inc. Replace ‘2022’ with the shortcode provided and save.

That’s it! That simple. It should be live now across your website. If you have a questions, do let me know!