WordPress Current Year Shortcode for Copyright Footers

A WordPress current year shortcode saves you from editing the copyright line every January. Put [current_year] in the footer once and it always shows the right year.

This version also handles the common “© 2019–2026” format: [current_year from="2019"] prints the start year, a dash and the current year.

The snippet

<?php
add_shortcode( 'current_year', 'dpc_current_year_shortcode' );

/**
 * [current_year] prints the current year.
 * [current_year from="2019"] prints a range such as "2019–2026".
 */
function dpc_current_year_shortcode( $atts ) {
	$atts = shortcode_atts( array( 'from' => '' ), $atts, 'current_year' );
	$year = (int) wp_date( 'Y' );
	$from = absint( $atts['from'] );

	if ( $from > 0 && $from < $year ) {
		return esc_html( $from . '–' . $year );
	}

	return esc_html( (string) $year );
}

Add it with Scripts Organizer

Scripts Organizer ships this snippet in its One-Click Import library. To add it by hand:

  • In wp-admin go to Scripts Organizer → Code Blocks → Add New and give the block a title.
  • Script location: PHP.
  • Trigger location: Everywhere. The shortcode then exists on every request that may render it, including block editor previews that go through the REST API.
  • Action hook: leave it empty. The code only registers filters and actions, so it can run while plugins load.
  • Paste the snippet into the PHP editor, enable the block and publish it.

The same code also works unchanged in a small plugin or an mu-plugin file in wp-content/mu-plugins/.

How it works

  • add_shortcode() registers [current_year]. The callback returns the string; a shortcode must never echo, or the year shows up above the content instead of in place.
  • wp_date( 'Y' ) uses the timezone from Settings → General. WordPress sets PHP’s default timezone to UTC, so the older date( 'Y' ) ignores your site timezone and can switch the year hours early or late on New Year’s Eve.
  • shortcode_atts() fills in missing attributes, and absint() turns from into a positive integer, so from="abc" is ignored instead of printed.
  • If from is the current year or later, only the current year prints, so you never see “2026–2026”.
  • esc_html() escapes the output before it reaches the page.

Use it

In a block theme, open the footer template part in the Site Editor, add a Shortcode block and type © [current_year from="2019"] Your Company. In a classic theme, a Shortcode block in a footer widget area works the same way.

Customise it

For a different format, change 'Y' to another PHP date format character, for example 'y' for a two-digit year.

Gotchas

  • Full-page caching serves stored HTML. The year changes when the cache is rebuilt; if you cache pages for weeks, clear the cache on 1 January.
  • The tag current_year has no prefix, because sites already use it in their footers. If another plugin registers the same shortcode, the one added last wins; rename the tag in add_shortcode() if the output looks different from what you expect.
  • Shortcodes are not processed in the site title, menu labels or post titles unless the theme runs do_shortcode() there.
  • For another small shortcode in the same style, see Post reading time shortcode.

In the Scripts Organizer library Import it with one click from Scripts Organizer.

// newsletter

Three tested WordPress snippets a week

Blocks, security, performance, Tailwind, PHP and React. Copy, paste, ship. You’ll also get DPlugins product updates. No spam, and you can unsubscribe anytime.

// newsletter

Three tested WordPress snippets a week

Blocks, security, performance, Tailwind, PHP and React. Copy, paste, ship. You'll also get DPlugins product updates. No spam, and you can unsubscribe anytime.