FixesWeb design

WordPress current date shortcode

By 11/02/2020 February 19th, 2020 No Comments

Adding the current date to a WordPress page or post

Instead of a using a plugin like wp time and date, we much prefer to use code to solve these little problems. Code is more efficient and provides a more secure way to customise your website. The plugin works great for newbies, but we like the slightly more advanced way.

If you would like to add today’s date eg: 27/02/2020, to your post or page, simply copy the code below into your theme’s functions.php file. Preferably into the child theme’s functions.php file as you won’t overwrite when updating your theme.

function date_shortcode($atts, $content = null) 
{
return ($content) ? date($content) : date("d/m/Y");
}
add_shortcode('curr_date', 'date_shortcode');

Add the shortcode

All you need to do then is paste the shortcode [curr_date] to your post or page content.

Please show some love for this post if it helped you and share if you have time. We have plenty of other WordPress fixes and tricks to see, please check them out.

Need a price for a new website instantly

Try our website cost calculator for free and get a price emailed to you.