How to check foe WordPress timezone type?

If you choose a city as a timezone it will save to the “timezone_string” option but if you choose a Manual Offset (UTC+1 for instance) it is saved to the “gmt_offset” option

if you need the gmt_offset then

<?php echo get_option(‘gmt_offset’); ?>

this will give you an integer like 2 or -2.

and if you need the timezone string use

<?php echo get_option(‘timezone_string’); ?>

this will give you a string like America/Indianapolis

But i the php code like this

$tzs = get_option(‘gmt_offset’);
$tzobj = timezone_open($tzs);
$now = date_create(‘now’,$tzobj );

when when theme is activated the wordpress defaults to UTC+0 because of which the $tzs will throw warning like

timezone_open(): Unknown or bad timezone (0)

How can i fix this? Can i make it work on both way?

Read more here:: How to check foe WordPress timezone type?

Leave a Reply

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