How To Create A Shortcode That Displays The Current Year On A WordPress Website

Here's the exact code you can add to your child theme's functions.php file to create a WordPress shortcode that dynamically displays the current year.

How To Create A Shortcode That Displays The Current Year On A WordPress Website

Here's the exact code you can add to your child theme's functions.php file to create a shortcode that displays the current year automagically:


✅ Step 1: Add this to the site or the site themes functions.php

function show_current_year() {
    return date('Y');
}
add_shortcode('current_year', 'show_current_year');

✅ Step 2: Use this Shortcode in your content

In any Text Module (or wherever shortcodes are accepted), simply add this shortcode:

[current_year]

This will display the current year dynamically every year — for example, 2025.

Enjoy!