Theme & Front End PHP Beginner

Add a [year] Shortcode for Copyright Notices

Add [year] and [copyright] shortcodes so your footer's copyright year updates itself every January.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 14 lines
// [year] → 2026
add_shortcode( 'year', function (): string {
	return wp_date( 'Y' );
} );

// [copyright] → © 2026 Site Name
// [copyright from="2019"] → © 2019–2026 Site Name
add_shortcode( 'copyright', function ( $atts ): string {
	$atts = shortcode_atts( [ 'from' => '' ], $atts, 'copyright' );
	$now  = wp_date( 'Y' );
	$from = absint( $atts['from'] );
	$span = ( $from && $from < (int) $now ) ? $from . '–' . $now : $now;
	return esc_html( '© ' . $span . ' ' . wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) );
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

Footers that say “© 2023” in 2026 make a site look abandoned. These shortcodes print the current year, or a full copyright line, wherever you put them.

How it works

[year] returns the current year in your site’s timezone using wp_date(). [copyright] builds a full line with the © symbol and your site title, and can show a starting year with from="2019".

Shortcodes work in posts, the Shortcode block, most page builders’ text elements and classic text widgets.

Things to watch

  • If your footer is cached by a page cache, the year updates when the cache is refreshed, which usually happens within hours.
  • Bricks and some builders support dynamic data tags for the year too.

How to test it

Add [copyright from="2019"] to your footer. It should show “© 2019–2026 Your Site”.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only