If you are trying to add today's date to a WordPress post, you will discover that their are several ways to accomplish this.
But, before you go wasting a bunch of time learning all the different ways that don't work, here are 2 simple ways to add today's date to a WordPress post or page.
There are two simple ways to add today's date to WordPress;
- installing a plugin
- adding piece of short code
The plugin method I do not recommend, only because it is a plugin. The code method I highly recommend, but if you are unfamiliar with how to add code, you may want to stick with the plugin method.
Add Today's Date to WordPress with a Plugin
If you would like to go the plugin way, remember that they may get outdated and or cause security issues. One that we found with great reviews and was up to date was the WP Date and Time Shortcode.
After installing the plugin, to add today's date is as simple as adding the shortcode [wpdts-date-time] to your post.
Add Today's Date and Time to WordPress with php Code
Don't let the php code part scare you, this is really not that difficult. However, if you are not using a child theme, then I may not recommend this technique. Using this method without a child theme would require you to replace the code in your themes function.php every time your theme was updated.
So, assuming you are using a child theme, here is how simple it is to add today's date.
- From your hosting file manager, navigate to wp-content -> themes -> [theme]-child.
- Right click on the functions.php file and click edit.
- Add the following code to the end of that file;
function displayTodaysDate( $atts )
add_shortcode( 'datetoday', 'displayTodaysDate');
//END Display Date
- Add the following shortcode in your post where you would like to insert today's date. Remove the highlighted underscore [_datetoday] and you will get 10/01/2022, and of course you can dress it up however you like by adding html color, size etc. or using your own css.
And that is all there is to it.
You may discover other ways or other plugins, but in the long run I believe you will return to one of these 2 methods to add today's date to a WordPress post.
About the Author:
The SEO-Alien is a project started in 2009 regarding all things online marketing. The site started out more of a diary of predictions, suggestions and references to things I frequently used for online marketing... before social media marketing was even an option.
I hope you find the information and tools presented here useful and something worth sharing with others.
If there is anything else about online marketing or any online advertising strategy you think would be helpful, please let me know.