Skip to main content
Login Join
Snippet · PHP

Current Year Shortcode

Shared by Moses Cursor Ssebunya · July 25, 2026 · @init

19 views
Back to Snippets

The Current Year Shortcode allows you to display the current year anywhere on your WordPress website using a simple shortcode.

Instead of manually updating the year in your footer, copyright notice, posts, or pages every new year, this snippet automatically generates the current year from WordPress. This is useful for keeping copyright text and other date-based content accurate without editing your site every January.

Functionality

This snippet registers a shortcode:

[year]

When added to a page, post, widget area, or footer section that supports shortcodes, it will output the current year automatically.

For example:

Copyright © [year] Your Website Name. All rights reserved.

Will display as:

Copyright © 2026 Your Website Name. All rights reserved.

The snippet uses WordPress’ built-in date function, so it follows the site’s configured timezone settings.

How to use

  1. Add the snippet to your WordPress site using a code snippets plugin or your theme’s functions.php file.
  2. Make sure the snippet is activated.
  3. Go to any page, post, footer, or widget area where you want the year to appear.
  4. Add the shortcode:
[year]
  1. Save or publish your changes.
  2. View the page on the frontend to confirm that the current year is displayed.

Cautions

Use this snippet carefully if another plugin, theme, or custom code already uses the [year] shortcode. WordPress shortcode names must be unique, so using the same shortcode name elsewhere may cause conflicts.

Avoid adding the snippet multiple times on the same website, as this may cause a PHP error due to duplicate function names.

For safer use on large or client websites, consider renaming the shortcode to something more unique, such as:

[current_year]

or:

[site_year]

Also, avoid placing this snippet directly in a parent theme’s functions.php file because theme updates may overwrite your changes. A code snippets plugin or child theme is safer.

add_action( 'init', 'register_current_year_shortcode' );

function register_current_year_shortcode() {
	add_shortcode( 'year', 'display_current_year_shortcode' );
}

function display_current_year_shortcode() {
	return esc_html( wp_date( 'Y' ) );
}
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments