WordPress shortcode to get current year

Posted on: April 24th, 2023
By: Tadeo Lemus

Add in your functions.php

function current_year( $atts, $content = null ) {

	$current_year = date("Y");

	return $current_year;

	// [currentyear]

add_shortcode( 'currentyear', 'current_year' );

If you want to use plain PHP, you can use:

$current_year = date("Y");

echo $current_year;

Have any questions or comments? Write them below!

Leave a Reply

Your email address will not be published. Required fields are marked *