How to display today’s date in the header of your WordPress site:

Sometimes it’s nice to display the current date in the header of your WordPress site. If for no other reason, site visitors will get the impression your site’s content is current and fresh. Some WordPress themes include a header widget area allowing you to accomplish this with ease, but for those which do not – follow along.

First things first. In your WordPress Admin, head over to Settings >>> General, and decide how you wish for your date to display.

As you can see, you have a lot of flexibility here as to how the date will display, including your own customization. Select what suits you best, then save your choice.

Next things next. You will need to add a code snippet to your theme’s header.php file. Caution – You really need to do this within your Child Theme, otherwise, your edits will be wiped-out the next time you update your site.

The basic code snippet to add to your theme’s header.php file is this:

<?php echo date(get_option('date_format')); ?>

You add this to the header.php file before the closing tag: /header. What this does is display the current date in your header based on the format you selected in Settings >>> General discussed above.

Cool enough, but you may need a bit more customization. If so, you can add to your snippet as needed. Here’s an example:

<div style="margin-left:70px; font-size:16px;">
			 | Rome, IT</div>

What this does, and looks like in your site’s header is this:

April 22, 2018 | Rome, IT

You can see from the code above, within the <div></div> tags, in addition to the needed date code, I have added some in-line CSS and text, such as margin and font size. You could also add other definitions such as font family. text color, padding, margin, etc., depending on what you think looks best on your site.

That’s it, enjoy! If faint-hearted in dealing with custom coding, I’ll be glad to take care of this for you, Just Call The WordPress Guy!

Share This