Insert the Current Date/Time in Posts or Pages

Sometimes, you may want to display the current date or time inside one of your posts and pages and have it update dynamically every time the page is loaded.

We can achieve this quite simply by creating an easy shortcode in your WordPress installation.

To do this, add the following code to the bottom of your functions.php file. This code includes a function which checks the current date/time and then returns it when the shortcode is inserted in a post or page. You can change the way the date/time appears by using PHP date formats; the way I’ve written the code in this tutorial will return a value such as May 18, 2011.

function displaydate(){
return date('F jS, Y');
add_shortcode('date', 'displaydate');

This entry was posted in Design. Bookmark the permalink.

Comments are closed.