This guide explains how to dynamically display the current year in WordPress posts. By using a shortcode to automatically generate the year, your content will always remain up-to-date without manual adjustments.
Steps to Show the Current Year in WordPress Posts
Log in to WordPress
Access your WordPress admin dashboard.
Navigate to the Theme Editor
In the dashboard’s left sidebar, click Appearance > Theme Editor.
Edit the Theme Functions File
In the right sidebar, locate and click on Theme Functions (functions.php) under Theme Files.
Add the Shortcode Function
Copy and paste the following code snippet at the end of the functions.php file:
function current_year() {
return date('Y');
}
add_shortcode('year', 'current_year');
Save the Changes
Click Update File to save the changes. The shortcode functionality is now active.
Using the Current Year Shortcode in Posts or Pages
Open the desired post or page in the WordPress editor.
Add the shortcode [year] where you want the current year to appear.
Example:
Copyright © [year] Your Company Name
Save your changes and preview the post or page.