Change the Timezone for the Divi Countdown Timer Module

Written by Dan Mossop

The Divi Countdown Timer module is great for adding countdowns to events or sale endings. By default, the countdown timer uses the timezone configured in WordPress Settings. However, there are times you may want to set a different timezone specifically for the countdown timer without affecting the rest of your site. Let's explore how to achieve both settings.

Set the Countdown Timer Timezone in the WordPress Settings

The Divi Countdown Timer module relies on the global timezone setting configured in WordPress. By default, this timezone can be set in the WordPress Admin Panel as follows:

  1. Go to WP Admin > Settings > General.
  2. Locate the Timezone option.
  3. Select your desired timezone from the dropdown menu.
  4. Save the changes.

Changing the timezone here will affect the entire site, including all time displays and the countdown timer module. This ensures consistent timekeeping across the site.

Set the Countdown Timer Timezone using PHP

If you prefer to change the timezone only for the Divi Countdown Timer module, you can do so by adding a custom PHP code snippet to your site. This method allows the countdown timer to use a different timezone independently of the global WordPress setting.

Here's the PHP code to achieve this:

/* === Change countdown timer module timezone === */
/* Src: https://divibooster.com */

function divibooster_custom_gmt_offset() {
    return '-5'; // Your custom GMT offset, e.g., for EST its -5
}

function divibooster_add_countdown_timer_timezone_filter( $props, $attrs, $render_slug, $_address, $content ) {
    if ( 'et_pb_countdown_timer' === $render_slug ) {
        add_filter( 'option_gmt_offset', 'divibooster_custom_gmt_offset' );
    }
    return $props;
}
add_filter( 'et_pb_module_shortcode_attributes', 'divibooster_add_countdown_timer_timezone_filter', 10, 5 );

function divibooster_remove_countdown_timer_timezone_filter( $output, $render_slug ) {
    if ( 'et_pb_countdown_timer' === $render_slug ) {
        remove_filter( 'option_gmt_offset', 'divibooster_custom_gmt_offset' );
    }
    return $output;
}
add_filter( 'et_pb_module_shortcode_output', 'divibooster_remove_countdown_timer_timezone_filter', 10, 2 );

/* === END: Change countdown timer module timezone */

You can add this into the functions.php file of a child theme, or via a plugin such as Code Snippets.
Here's what the code is doing:

  1. Custom GMT Offset Function: The diviBooster_custom_gmt_offset function sets the custom GMT offset. For example, return '-5' sets the timezone to EST. Set this to your desired timezone offset.
  2. Adding the Filter: The diviBooster_add_countdown_timer_timezone_filter function adds the custom GMT offset filter specifically for the et_pb_countdown_timer module.
  3. Removing the Filter: The diviBooster_remove_countdown_timer_timezone_filter function removes the custom GMT offset after the countdown timer has been rendered to avoid affecting other modules.

By implementing this code, you ensure that your Divi Countdown Timer module displays the correct time based on a specified timezone while leaving other parts of your site unaffected. This method is particularly useful for sites with users in different timezones or for events that need a distinct countdown timezone.

Run PHP Code Directly in Your Divi Layouts

Unlock custom functionality in your Divi Countdown Timer with the Divi PHP Code Module. Seamlessly add PHP code for timezone-specific countdowns directly into your layout, enhancing control and customization.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

0 Comments

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

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

We may earn a commission when you visit links on our website.

Latest From Divi Booster

How to Add the Post Status in Divi's Dynamic Content

Divi's Dynamic Content feature is great for enhancing your post/page templates with post-specific information. While Divi includes an option to show information such as the Post Created Date using Dynamic Content, there is no equivalent option for the Post Status....

Fix Divi Text Module "Regular" Font Weight Not Working

Are you encountering an issue where the font weights in Divi's Text Module don't seem to apply as expected? In particular, you might find that when you set the text module's body text font weight to "Regular", your font is actually assigned a weight of 500 instead of...

Make the Divi Gallery Module Swipeable

The Divi Gallery Module comes with a slider mode that lets you display images in a slider with clickable left/right arrows to scroll through the images. For mobile / touchscreen users, you can improve the user experience by allowing your user to swipe to navigate to...

How to Use Divi Dynamic Content in Woo Modules Product Selector

Divi's Dynamic Content is a powerful feature that lets you populate your Divi modules and theme builder templates with data pulled in various sources, such as custom fields. This allows for efficient organization and maintenance of your sites.Unfortunately, Divi's...

Random Divi Posts