How to Display Today‘s Date in WordPress (2 Easy Methods)

Hey there, WordPress user! Are you looking to show the current date on your website? You‘ve come to the right place. Displaying today‘s date can be a small but powerful addition to your site that provides helpful context and keeps your content fresh.

In fact, a recent study found that 75% of people trust content more when it includes a publication date (Source: Content Marketing Institute). Showing the current date is an easy way to boost your credibility and show visitors that your site is actively maintained.

Plus, there are tons of creative ways to use dates throughout your WordPress site to improve the user experience. For example:

  • 34% of consumers say they‘re more likely to make a purchase if there‘s a countdown timer (Source: Sleeknote). Displaying the current date along with an upcoming sale end date is a proven way to create urgency.
  • Top food bloggers update their content every 1-3 months (Source: SEMrush). Showing the "last updated" date instills confidence that recipes are accurate and reliable.

Whether you run a blog, ecommerce store, membership site, or anything in between, showing today‘s date is a simple yet effective addition. And the good news is, you don‘t need any special date plugins or complicated setups to do it in WordPress.

In this guide, I‘ll show you two easy methods to display today‘s date anywhere on your site:

  1. Adding a PHP code snippet
  2. Using a WordPress shortcode

I‘ll walk you through each method step by step, with bonus tips and examples to help you get the most value from dates. By the end of this post, you‘ll be able to expertly add the current date to your WordPress site in a snap!

Let‘s get started.

Method 1: Display the Date with PHP Code

For the tech-savvy folks out there, you can display today‘s date in WordPress by directly adding a simple PHP code snippet to your theme template files, like header.php or footer.php.

Here‘s the basic code to show the current date:

<?php echo date(‘F j, Y‘); ?>

When added to your site, this will display the full name of the month, the day of the month, and the four digit year, like this:

August 27, 2023

Easy, right? But what if you want to customize the way the date looks to better match your site‘s style and format? No problem! You can adjust the date format by changing the characters inside the single quotes of the code.

Here are some of the most common formatting options:

CodeOutput
jDay of the month without leading zeros (1 to 31)
dDay of the month, 2 digits with leading zeros (01 to 31)
DA textual representation of a day, three letters (Mon through Sun)
l(lowercase ‘L‘) – A full textual representation of the day of the week (Sunday through Saturday)
FA full textual representation of a month (January through December)
mNumeric representation of a month, with leading zeros (01 through 12)
MA short textual representation of a month, three letters (Jan through Dec)
YA full numeric representation of a year, 4 digits (e.g. 2023)
yA two digit representation of a year (e.g. 23)

So for example, if you wanted to display the date like "Sun, Jan 3, 2023", you would use:

<?php echo date(‘D, M j, Y‘); ?>

Feel free to mix and match the codes to create a date format that suits your needs. You can even add extra characters inside the single quotes, like spaces, commas, or other words, to customize it further:

<?php echo "Today‘s date is " . date(‘l, F j, Y‘); ?>

This would display something like:

Today‘s date is Monday, August 27, 2023

Pro Tip: If you want to display the date in a different language, you can use the PHP setlocale() function before your date code, like this:

<?php
setlocale(LC_TIME, ‘fr_FR.utf8‘); 
echo strftime("%A %e %B %Y");
?>

This will show the French version of the date.

Bonus: You‘re not limited to just displaying the date either. You can also show the current time by adding some additional formatting codes:

<?php echo date(‘F j, Y, g:i a‘); ?>  

This would output:

August 27, 2023, 2:36 pm

Pretty cool, huh?

Now, I know what you might be thinking: "That‘s great and all, but I‘m not really a code person. Is there an easier way?"

Absolutely! That brings us to…

Method 2: Display the Date with a Shortcode

If you‘re not comfortable messing with your theme files and PHP, you can achieve the same result by creating a WordPress shortcode instead.

A shortcode is basically a small piece of code that you can drop into any post, page, or widget to perform a specific function – like displaying today‘s date! Once set up, all you have to do is type the shortcode where you want the date to show up and voila.

Here‘s how to create a date shortcode in WordPress:

  1. First, you‘ll need to install a plugin that allows you to create custom shortcodes. I recommend the free Insert PHP plugin or Code Snippets if you want something more advanced.

  2. Once the plugin is activated, go to the settings page and paste in the following code:

function display_todays_date() {
return date(‘F j, Y‘);  
}
add_shortcode(‘todays-date‘, ‘display_todays_date‘);
  1. See that part in the middle where it says "F j, Y"? That controls the date format just like in the PHP method above. Customize that section using the same formatting codes we covered earlier.

  2. Click save, and your new shortcode is ready to go! Now just type [todays-date] (including the brackets) wherever you want the current date to appear.

For example, you could add it to a post like this:

Hello everyone! Welcome to our daily update for [todays-date]. 
Here‘s what‘s new...

And it would render on the front end like:

Hello everyone! Welcome to our daily update for August 27, 2023.
Here‘s what‘s new…

Super simple, right? But again, don‘t be afraid to get creative with your shortcode to make it work for your unique content.

For instance, let‘s say you run a local dog grooming business and want to display a notice about your current availability on the homepage. You could create a custom shortcode like this:

function display_grooming_availability() {
return "We currently have appointment openings starting " . date(‘l, F j, Y‘) . ". Call now to book!"; 
}
add_shortcode(‘grooming-openings‘, ‘display_grooming_availability‘);

Then add [grooming-openings] to your homepage content to show a message like:

We currently have appointment openings starting Monday, August 27, 2023. Call now to book!

How‘s that for effective marketing? By getting a bit creative, you can use shortcodes to display all kinds of helpful date-related messages.

Best Practices & Tips for Showing Dates

Alright, now that you know how to display today‘s date with either PHP or shortcode, let me share a few expert tips to really make it shine:

  1. Keep your date format consistent. However you choose to display the date, stick with the same format throughout your entire site. Consistency improves usability and keeps things looking polished.

  2. Don‘t forget about localization. If you have a multilingual site or audience, consider showing dates in a localized format. You can achieve this with the PHP setlocale() function or a plugin like WPML.

  3. Style the date display with CSS. Want to change the color, font, or size of the date? You can target it with CSS using the .date class for PHP or a custom class for your shortcode. For example:

.date {
color: #ff0000;
font-weight: bold;  
}
  1. Mobile-friendly is a must. Always check how the date displays on different screen sizes and devices. Make sure it doesn‘t cause any weird wrapping or spacing issues on mobile.

  2. Combine with other relevant info. Dates are often most useful when paired with other key details. For instance, an event listing could show the current date along with the event date, time, and location.

  3. Only show dates when needed. As helpful as dates can be, don‘t feel like you need to plaster them everywhere just because you can. Be intentional and use them where they genuinely add value for users.

By following these tips, you‘ll be well on your way to showing dates like a WordPress pro.

Frequently Asked Questions

Before we wrap up, let me address a few common questions I hear about displaying dates in WordPress:

What happens if I change my site language? Will the dates automatically translate?

Not necessarily. While WordPress will use the site language for things like the comment date and post publish date, any dates you display with the PHP or shortcode methods will need to be manually translated using setlocale() or a localization plugin.

Can I show a different date besides today?

Yep! Both the PHP and shortcode methods can be easily tweaked to show a different static or relative date. For example, to show tomorrow‘s date, you could use:

<?php echo date(‘F j, Y‘, strtotime(‘+1 day‘)); ?>

Or to show a specific date, like January 1, 2023, you could use:

<?php echo date(‘F j, Y‘, strtotime(‘2023-01-01‘)); ?>  

I added the date code/shortcode but it‘s not showing up. What‘s wrong?

First, double check that you added the code to the correct template file or page/post content. If it‘s still not showing, make sure there are no syntax errors in the code by comparing it character by character to the examples in this post.

Also, if you‘re using a shortcode, ensure that the shortcode name matches what you have in the code. For example, if your shortcode function says "add_shortcode(‘todays-date‘)", make sure you‘re typing [todays-date] (not [date] or something else).

My date is showing the wrong time or timezone. How do I fix that?

First, confirm that your WordPress settings are correct by going to Settings > General and checking the timezone. If it‘s inaccurate, update it and see if that resolves the issue.

If the timezone settings are correct, you can use the PHP date_default_timezone_set() function above your date code to manually adjust the timezone, like this:

<?php
date_default_timezone_set(‘America/Los_Angeles‘);
echo date(‘F j, Y‘); 
?>

Just replace "America/Los_Angeles" with your desired timezone. Here‘s a full list of supported timezones.

Putting It All Together

Well folks, that concludes our deep dive into displaying today‘s date in WordPress! Let‘s recap what we learned:

  • Showing the current date is an easy way to add credibility, freshness, and context to your WordPress site
  • There are two main methods to display today‘s date: adding PHP code or using a shortcode
  • The PHP method involves pasting a code snippet into your theme template files, while the shortcode method uses a plugin to create a shortcode you can add anywhere
  • You can customize the date format, language, and styling with a few simple tweaks to the code
  • Dates are most effective when used intentionally and combined with other relevant content

I hope this guide has given you the knowledge and confidence to start using dates on your own site in a way that genuinely enhances the user experience. Trust me, even something as small as showing the current date can go a long way in building trust and engagement with your audience.

So what are you waiting for? Go add some dates and watch your site‘s credibility soar!

And hey, if you found this guide helpful or have any creative ways you use dates on your own WordPress site, I‘d love to hear about it. Leave a comment below and let‘s keep the conversation going.

Happy dating, WordPress friends!

Did you like this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.