Automatically update the year (e.g. in © Copyright in the footer)
Tired of manually changing the dates on your website every year? Then I've got just the thing for you.
With a simple 4 lines of PHP code, WordPress automatically sets the current year. Provided that your server's time is set correctly. However, I would assume that this is the case.
1a. Add this code to your functions.php (my recommendation!)
The best way to do this is to use a Child themewhich I have described in more detail in this blog post.
function year_shortcode() {
$year = date('Y');
return $year;
}
add_shortcode('year', 'year_shortcode');
1b. Insert this code with the plugin code snippet
If you are not so familiar with the WordPres folder structure and PHP, you can also implement this code risk-free via code snippets. However, I strongly recommend that you implement it using method 1a in the child theme. Nevertheless, I would like to show you a possible alternative.
To do this, install the plugin Code Snippets and create a new snippet with the above code.
Practical The great thing about the plugin is that you cannot "destroy" your site with it. The plugin checks whether it causes an error when the code is activated. If so, the code will not be activated.
2. insert year in square brackets as the year
Then you just have to insert the shortcode "year" in the square brackets, which reads out the year of the server time or date, into the text instead of the manual year.
The result: The year is now updated automatically
© 2025 CS Webdesigns | Imprint | Privacy Policy
The cool thing about this post is that it doesn't matter when you read it, it will always show the current year 😉
Conclusion
With just four lines of code, you can save yourself an annoying annual ritual - especially if you maintain several websites. I recommend you implement it with variant 1a. If you are not yet using a child theme, take a look at my Blog post for this. This is also very easy and quick to do.
0 Comments