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 Posts

Set Custom CSS IDs for Individual Divi Accordion Items

Assigning unique CSS IDs to specific Divi Accordion items allows for precise control over styling, targeting, and linking within your page content. This ability is particularly useful when you want to apply custom designs or create anchor links to particular accordion...

Enable Swipe Navigation in the Divi Gallery Lightbox

Enabling swipe navigation in the Divi Gallery module's lightbox allows users to seamlessly browse through gallery images by swiping left or right, creating a more interactive and mobile-friendly experience. This functionality can significantly improve user engagement...

Disable Slide-In Animation for Divi Gallery Grid Images

Control how images appear in your Divi Gallery module by toggling the slide-in animation effect for grid layouts. Disabling the slide-in animation allows gallery images to load instantly and appear statically, providing a faster and distraction-free browsing...

Control Image Count Display in Divi Gallery Lightbox

Displaying or hiding the image count in the Divi Gallery module’s lightbox can help customize the user experience, depending on whether you want to give visitors an indication of gallery progress or prefer a cleaner, distraction-free view. The ability to toggle this...

Hide Gallery Image Titles in the Divi Lightbox Overlay

Displaying image titles in the lightbox overlay of the Divi Gallery module can sometimes be distracting or unnecessary, depending on your website’s design and user experience goals. Hiding these titles creates a cleaner and more focused viewing experience for visitors...

Random Posts