How to show the current year in WordPress posts
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.
Showing the current year
To show the current year in WordPress posts, follow these steps:
- Log in to WordPress as the administrator.
- On the Dashboard in the left sidebar, click Appearance, and then click Theme Editor:
- In the right sidebar, under Theme Files, click Theme Functions (functions.php).
- 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’); - Click Update File. WordPress saves the changes to the functions.php file.
- 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:
Read more – How to customize the number of search results displayed in WordPress