Keeping the year up-to-date in WordPress

Websites often have the current year in the footer with a copyright notice. If the year is manually entered it can easily get out of sync. Remembering to change it every year is easily forgotten and easy to miss. Plus, as you only change it once a year you’ve probably forgotten where it is actually defined, so changing it takes longer than you’d hope. It is the sort of annoying task that should just go away so you never have to worry about it. Here is how you can automatically display the current year on a WordPress site.

If the year is set within the PHP templates you can change it to use the following. This uses the PHP strftime() function to get the current year.

<?php echo strftime('%Y'); ?>

If year is set somewhere within the WordPress admin you can normally use a shortcode.

For example, if it’s defined within a text widget for a widget area. You can define a short code for the current year in the functions.php file for the current theme via:

add_shortcode('current-year', function(){
    return strftime('%Y');

Then within the text area in the admin you can use:


If short codes are not enabled for your text area, you can enable this in the theme’s functions.php file via:

add_filter('widget_text', 'do_shortcode');
If you enjoyed this post, consider leaving a comment or subscribing to the RSS feed.
This site uses cookies. Find out more about cookies.