This article describes how to show the current year in WordPress posts. By automatically generating the current year using a shortcode, you can ensure that your posts are always up-to-date.
To show the current year in WordPress posts, follow these steps:
Copy the following code snippet and then paste it at the bottom of the functions.php file:
function current_year() { $year = date('Y'); return $year; } add_shortcode('year', 'current_year');
The current year functionality is now enabled, but you must update the post or posts where you want it to appear. To do this, open a post or page on the site, and then type [year] where you want to display the current year. For example:
Save your changes, and then view the post:
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.
Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.
We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.