Show the current date in WordPress without a plugin

Show the current date in WordPress without a plugin - Bent Corner

I wanted a way of displaying the current date in WordPress. Ideally, I wanted to use a shortcode that would display it.

After I checked out the built-in shortcodes native to WordPress, and verified there was not a shortcode for displaying the current date, I looked for a plugin that did it. I found quite a few plugins that generated a shortcode to display the current date. I then thought about adding yet another plugin to my website just to display the date.

I decided to create it myself without a plugin.

This is what I came up with:

I copied the above code and pasted at the end of the function.php file in my website’s theme folder. I then placed the following shortcode where I wanted the current date to be displayed:

[[display_current_date]]

The result was the following:

[display_current_date]

I formatted the PHP date() function with the following format parameters:

l” – A full textual representation of the day of the week.
j” – The day of the month without leading zeros.
F” – A full textual representation of a month, such as January or March.
Y” – A full numeric representation of a year with four digits.

If you would like to use this code, but want to change the way the current date gets displayed, you can see a full list of the format parameters by going here.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top