Skip to content

Instantly share code, notes, and snippets.

@robhob
Last active May 2, 2019 02:27
Show Gist options
  • Save robhob/9b8e0e3c114a31a80082af3f0fc49b5f to your computer and use it in GitHub Desktop.
Save robhob/9b8e0e3c114a31a80082af3f0fc49b5f to your computer and use it in GitHub Desktop.
This function was written to work with the free "Content Visibility for Divi Builder" plugin (https://wordpress.org/plugins/content-visibility-for-divi-builder/). Add the following line to the Content Visibility field of the chosen Section or Module: is_daytime();
function is_daytime() {
$time_now = date("H:i a");
$time_now = DateTime::createFromFormat('H:i a', $time_now);
$morning = "7:00 am";
$morning = DateTime::createFromFormat('H:i a', $morning);
$evening = "8:00 pm";
$evening = DateTime::createFromFormat('H:i a', $evening);
if ($time_now >= $morning && date("h:i") <= $evening)
{
return 1;
}
else {
return 0;
}
}
@peeayecreative
Copy link

Thank you for this. Will this show the module between 7:00 AM and 8:00 PM, and hide the module from 8:00 PM to 7:00 AM?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment