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!

Leave a Reply

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

    © Copyright 2025 Edward Phelps. All rights reserved.
    Privacy   |   Terms

    Subscribe

    Access exclusive content and get The Web Guy Newsletter.
    The Web Guy Logo-Box Black
    • Subscribe for access to premium content.