---
title: "Generating the current year without modifying the theme"
description: "Although it may seem unbelievable, there are a great many themes for WordPress, both free and premium, that do not generate the current year dynamically. This functionality is very useful for being able to add the year in force in"
url: https://artprojectgroup.com/generating-the-current-year-without-modifying-the-theme
date: 2017-01-24
modified: 2023-02-12
author: "Art Project Group"
image: https://artprojectgroup.com/wp-content/uploads/2023/02/wordpress-blog.webp
categories: ["Tutorials"]
tags: ["functions.php", "PHP", "WordPress"]
type: post
lang: en-US
---

# Generating the current year without modifying the theme

Although it may seem unbelievable, there are a great many themes for WordPress, both free and premium, that do not generate the current year dynamically. This functionality is very useful for being able to add the year in force in the copyright of the footer, and in those themes in which it is not generated automatically thanks to a variable or to a shortcode native to the theme itself, one of these actions has to be taken:

**Change the year in force at that moment in the options of the theme every year.**

It is the simplest option of all, but also the most tedious and the least advisable, since the most likely thing is that you will remember some time in April that the year currently shown on your website is out of date.

**Change the code of the *footer.php* template in the child theme.**

This option is also simple, but it is going to force you to keep an eye on the successive updates of the parent theme in order to incorporate the code changes that are made to this file in future versions of the theme. That is why we do not recommend it to you either.

**Customise the hook that generates the copyright by changing the filter or the action in charge of doing it.**

You have to make this customisation in the *functions.php* file of the child theme and, although creating it is relatively simple, it requires knowing the hook that the author of the template in question has created to carry out this task, and having sufficient knowledge of PHP and of programming in WordPress. To achieve it you will first have to look for the hook in the PHP code that is in the *footer.php* template. Therefore, unless you are very clear about what you are looking for and what you are doing, we do not recommend this option to you under any circumstances.

**Create our own shortcode in the *functions.php* file of the child theme.**

We have left for last the simplest and the most advisable option of all the options proposed.

### Solution

To achieve it we are going to create a shortcode thanks to a simple and tiny PHP function that we will add in the *functions.php* file of the child theme.

The PHP function we propose to you today is the following:

Copy to clipboardSyntax Highlighter/*
Shows the current year in the footer
*/
function apg_current_year() {
return date( 'Y' );
}
add_shortcode( 'current_year', 'apg_current_year' );
Thanks to this incredibly simple piece of PHP code you will be able to add the current year anywhere on your website by writing this simple shortcode wherever you need it:

Copy to clipboardSyntax Highlighter[ano_actual]
This tiny piece of code must return this to you: 2026, the year in course at this moment. As you can see, in this simple and straightforward way you now have a solution for a problem that we still do not understand how it is not solved in 100% of themes. As always, we hope that the proposal we are making to you is useful and functional. Does your theme not have this functionality either? How have you solved it? We look forward to your comments and opinions on this post.
