Display Current Year in WordPress

Quick Summary

  • Register a year shortcode with add_shortcode() that returns the four-digit current year, so a footer copyright line never needs editing.
  • Shortcodes run in post content, the Shortcode block and the Text widget, but theme footer fields only if the theme supports them.
  • WordPress sets PHP's timezone to UTC, so date() returns the UTC year, which can differ around New Year; wp_date() uses the site timezone.

Hard-coding the year in your footer copyright means editing it every January. This WordPress snippet registers a [year] shortcode that always prints the current year, so a line like © [year] Your Company stays up to date on its own.

Add it to your child theme’s functions.php or to a small custom plugin.

PHP
function currentYear( $atts ){
    return date('Y');
}
add_shortcode( 'year', 'currentYear' );

How it works

add_shortcode() tells WordPress to call currentYear() whenever it finds [year] in your content. The function returns date('Y'), the four-digit year. Shortcode callbacks must return their output instead of echoing it, otherwise the text shows up in the wrong place. The $atts parameter isn’t used, so the shortcode takes no options.

  • Shortcodes work in post and page content, the Shortcode block and the Text widget. A footer text field in your theme’s options only runs them if the theme supports it. For a field built with Advanced Custom Fields (ACF), adding shortcode support to ACF text fields takes one filter.
  • WordPress sets PHP’s default timezone to UTC, so date('Y') returns the year in UTC. For a few hours around New Year it can differ from your site’s local year. wp_date( 'Y' ) uses the timezone from Settings > General instead.
  • If another plugin registers its own [year] shortcode, the one registered last wins. Pick a more specific name if you run into a conflict.
Share on X (opens in a new tab) Share on LinkedIn (opens in a new tab) Share on Facebook (opens in a new tab)

ChatGPT (opens in a new tab) Claude (opens in a new tab) Gemini (opens in a new tab) Perplexity (opens in a new tab) Grok (opens in a new tab)

More Insights

See More