WordPress – Current Year Shortcode

WordPress - General Functions Shortcodes PHP

Snippet Overview

WordPress – Current Year Shortcode

This function allows you to add a dynamic year anywhere on your site using a shortcode. The shortcode displays the current year and will update automatically. This is particularly useful for the copyright line which generally appears in the footer at the bottom of your website.

To use the function as a standard WordPress shortcode add the following to your site:

[year]

To hardcode this function into your theme use the following PHP script:

<?php echo do_shortcode("[year]"); ?>

To enable this function you need to add the following to your WordPress theme’s functions.php file.

function year_shortcode() {
	$year = date('Y');
	return $year;
}
add_shortcode('year', 'year_shortcode');
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply