Dynamic Year Shortcode

PHP Code Snippets/Functions

Shortcode that outputs the current year. Insert the code below in your functions.php file.


function current_year() {
    $year = date('Y');
    return $year;
}

//You can change the shortcode from [year] to any text you want by changing the first parameter of the add_shortcode function below.
add_shortcode('year', 'current_year');

Here is an example of the code applied in Real Computer Solutions.

Front-end
Back-end / Editor

Leave a Reply

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