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:

1/* === Change countdown timer module timezone === */
2/* Src: https://divibooster.com */
3
4function divibooster_custom_gmt_offset() {
5 return '-5'; // Your custom GMT offset, e.g., for EST its -5
6}
7
8function divibooster_add_countdown_timer_timezone_filter( $props, $attrs, $render_slug, $_address, $content ) {
9 if ( 'et_pb_countdown_timer' === $render_slug ) {
10 add_filter( 'option_gmt_offset', 'divibooster_custom_gmt_offset' );
11 }
12 return $props;
13}
14add_filter( 'et_pb_module_shortcode_attributes', 'divibooster_add_countdown_timer_timezone_filter', 10, 5 );
15
16function divibooster_remove_countdown_timer_timezone_filter( $output, $render_slug ) {
17 if ( 'et_pb_countdown_timer' === $render_slug ) {
18 remove_filter( 'option_gmt_offset', 'divibooster_custom_gmt_offset' );
19 }
20 return $output;
21}
22add_filter( 'et_pb_module_shortcode_output', 'divibooster_remove_countdown_timer_timezone_filter', 10, 2 );
23
24/* === 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

Enable Automatic Looping for YouTube Videos in the Divi Video Module

Enabling automatic looping for YouTube videos in your Divi video module ensures that content plays seamlessly and continuously without interruption. This feature can enhance user engagement, highlight key information, or create dynamic visual effects on your website....

Hide Video Controls in Divi Video Module

Disabling YouTube video controls in the Divi Video Module helps create a seamless, distraction-free viewing experience for your site visitors. This approach is useful when you want full control over how your video content appears and is interacted with on the page, or...

Mute YouTube Videos by Default in the Divi Video Module

In the Divi Video Module, starting your YouTube videos muted by default can create a more user-friendly browsing experience on your webpage. It is particularly beneficial for reducing distractions, enhancing visitor engagement, and providing a seamless content preview...

Autoplay Videos in Divi Video Module

Enabling videos in your Divi video module to start playing automatically can enhance both the site's design and user engagement. To ensure full compatibility with browser requirements, such as Chrome's autoplay policy, it's often necessary to start your videos muted...

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....

Random Divi Posts