Skip Navigation

[Closed] Is there a way to show html based on condition of the current Eastern time?

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Shane 5 years, 11 months ago.

Assigned support staff: Shane.

Author
Posts
#325925

I am trying to: Show conditional HTML based on the current time of day in New York

I visited this URL:

I expected to see:

Instead, I got:

is it possible to show conditional HTML in a Content Template or View ,based on the current time in NYC (Eastern Time)?

if it's before 5am, I want to show certain content, if it's later than 5am, i want to show alternate content.

I want to avoid the user having to input a custom field date.

Is this possible? Thanks in advance for your help 🙂

#326011

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Katrina,

Thanks for contacting our support forum.

I believe this is possible by using some custom code to get the current time and compare it to a fixed time.

However to confirm my assumption I would need to perform some tests before giving you a definitive answer.

I'll get back to you once i've done this test.

Thanks

#326020

Hi Shane,

That sounds promising! Please let me know what you discover...

Thank you for taking the time.

Katrina

#326025

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Katrina,

So i've found a way to make this work for you.

Add this to your theme's functions.php file.

// Add Shortcode
function new_time() {

  // Code
ini_set('date.timezone', 'America/New_York');

$time = date('H', time()); // 12:00:00

return $time;

}
add_shortcode( 'new_time', 'new_time' );

The next step is to go to views -> settings -> compatibility and add "new_time" to the 3rd party shortcodes argument area.

Once you have done that then you can use the following shortcode.

[wpv-conditional if="( '[new_time]' lt '5' )"]It's time[/wpv-conditional]

[wpv-conditional if="( '[new_time]' gt '5' )"]It's not time[/wpv-conditional]

The first one is for all the content before 5am and the second is for content after 5am.

Please let me know if this helps.

Thanks

The topic ‘[Closed] Is there a way to show html based on condition of the current Eastern time?’ is closed to new replies.