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

Category(ies): Wordpress
Published on 3.01.2023
Web Designer

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 & developer with over 8 years of experience in WordPress and web development. He develops conversion-optimized websites & online stores that perfectly combine design and function to make companies successful online. In addition to his work, he travels around the world and is inspired by new impressions.

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 einfache Schritte zur automatisch aktualisierten Jahreszahl

1a. Füge diesen Code in deine functions.php ein (meine Empfehlung)

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.

Installiere dir dazu das Plugin Code Snippets und erstelle ein neues Snippet mit dem oben genannten Code.

Convert year into code snippets

Praktisch ist an dem Plugin übrigens, dass du deine Seite damit nicht „zerstören“ kannst. Das Plugin prüft bei Aktivierung des Codes, ob es einen Fehler verursacht. Falls ja, wird der Code nicht aktiviert.

2. Setze [year] als Jahreszahl ein

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

Fazit: Die Jahreszahl aktualisiert sich von nun automatisch

So einfach sparst du dir mit vier Zeilen Code ein nerviges, jährliches Ritual – vor allem wenn du mehrere Webseiten pflegst. Ich empfehle dir, es mit Variante 1a umzusetzen. Wenn du noch kein Child-Theme verwendest, sieh dir meinen Blog-Beitrag dazu an. Auch das ist sehr einfach und schnell erledigt.

Comments

0 Comments

Submit a Comment

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

en_USEN

Data protection consent