Show Current Date, Month, Year in WordPress With Shortcode
I had some articles where I had to show the current month and year. Now it’s an annoying job to manually update all those articles once the month ends.
So, I needed something that would update the month and year automatically.
Hence, I created a shortcode. Now, instead of putting the month, I would just put the shortcode.
As a result, once the month ends, shortcode will update it automatically.
Since I needed something like this, I thought there could be others who would need something like this. So, I made a plugin of it and submitted to the repository.
You can get the plugin here – Shortcode For Current Date
How To Show Current Date, Month, Year in WordPress
As the name suggests, you can show the current date, month or year with the shortcode.
Download and install the plugin and you’re ready to go.
After installing the plugin, in your post editor just put [current_date] where you want to show the date.
Here’s a demo. Today’s date is: 20th January 2018
It’s as simple as that.
Now, to show the month or year you would have to add something to the shortcode.
Let’s say, You want to show the current month and year. To do that, you would need to write the shortcode like this: [current_date format='F, Y']
Output of this shortcode will be the current month along with the year and that is January, 2018
The shortcode basically uses the PHP date function to generate the date, month or year. That means, you can use any format the function accepts.
Check out the date formats and use the ones that suits your needs.
Just remember to use the ‘format’ attribution. Otherwise, your shortcode will not generate the date or month or year correctly.
If you have any questions or suggestions, don’t forget to use the comment box.