DEV Community

sinanisler
sinanisler

Posted on

Display Current Year Short Code, WordPress

Add this to your functions.php

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

Enter fullscreen mode Exit fullscreen mode

This code will allow you to use [current_year] in your posts or pages, and it will output the current year.

Once the code is added to your theme or plugin, you can simply insert [current_year] anywhere in your posts, pages, or widgets to display the current year.

have fun with this little snippet :)

if you need more snippets like this have look at my tiny library sinanisler.com

Top comments (0)