Local Time in London – Display in a WordPress website

Local Time in London – Display in a WordPress website featured image
(Last Updated On: December 1, 2017)

A long while back, I wrote a short piece about how to make Linux servers set their local time to Europe -> London, which you can find here.

Today, I’m going to show you how to post a quick snippet into your WordPress to allow you to display what the local time is anywhere in the world. For us, we are on Europe/London time, and so, below, here is that very feature:

Local Time in London is [now_time]

The above tells you the local time in London… cool, huh?!

How to Make WordPress display the current time in a place, using a shortcode

This is a pretty cool little shortcode, which you might use to display times around the world… London, Paris, Milan, New York, Wherever-you-are…

The above code should be added to your theme’s functions.php file, or a helper plugin.

How to display it

Simply insert the relevant shortcode into your WordPress post or page, once you have saved the above function into your site’s active theme:

now_time

You’ll need to wrap this in square brackets “[” and “]” in your post or page.

What it does

This code creates a little function which sets the timezone to be the one we want (in this case, Europe/London), then uses PHP’s “date” function to ouput a formated “date” which is just the hours (one digit) minutes and AM or PM – in this case that is:

$i = date('g:i A');

You can find out more about PHP’s date function, here. But suffice it to say, different characters relate to different displays. Have a play with this!

This can be used to insert today’s date and time in a nice sentence too, for some dynamic content in your post. Like right now, in London, it is [now_time].

Leave a comment below if this helped you to insert the time in your WordPress website using a shortcode, or even if this only helped you to know what time it is, right now, in London!! 🙂

Leave a Reply

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

Silicon Dales