How the year is automatically updated on your website (e.g. in the footer ©)

Category(ies): Wordpress
Published on 3.01.2023
Set up SMTP sending in WordPress with Microsoft 365

What you can expect in this article:

Put an end to the annual routine of updating the year (e.g. in the copyright, but also possible everywhere else) in the new year. I'll show you a very simple trick to keep the year up-to-date automatically.
Christian Strasser Webdesigner

About the author:

Christian is a web designer and developer with over 8 years of experience in WordPress and web development. He develops conversion-optimized websites and online stores that perfectly combine design and functionality to make companies successful online.

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.

2 easy steps for automatically updated year

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.

// COPYRIGHT YEAR AS SHORTCODE //
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 Code Snippets plugin and create a new snippet with the above code.

Convert year into code snippets

The practical 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. enter 2026 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.

Enter the correct year in the copyright

Conclusion: The year will now update automatically

This is how you can save yourself an annoying, annual ritual with four lines of code – especially if you maintain multiple websites. I recommend you implement it with variant 1a. If you don't use a child theme yet, check out my blog post about it. That's also very easy and quick to do.

Comments

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Data protection consent