Conditions to have an image only appear according to the time

Hi ThemeCo!

I’ve got three images within a header- and only one of which I want to show based upon the time of the day.

Reading this: https://theme.co/docs/conditions-and-assignments I didn’t see this topic directly addressed.

In regard to one of those images, I’ve applied the following condition:

Can you help with the correct syntax?

Thanks!

Hi @ChadAustin,

Thanks for reaching out.
You need to add the DateTime in the proper format as shown in the given screenshot. I would suggest you select the date from the dropdown Calendar that appears with the value.

Hope it helps.
Thanks

Hope you don’t mind me commenting, but I read this earlier and think Tristup misunderstood the question. You mean the condition should depend on the time of day, ie: it happens every day at the set time?
If so, then I think the condition field on the left side should be set to global time this will be the local time of the server:
{{ global.time({"format":"H:i:s"}) }}

And then the field on the right could be something like:
00:09:00

Screenshot 2025-03-05 at 15.40.20

1 Like

Thanks to you both for responding.

Yes, spedney, you are correct… and I was trying to figure out how to formulate my question back to tristup when I saw your answer because I was thinking the exact same thing you were: this is meant for every day and it seemed his answer was for that calendar date.

So thanks for catching that!

I’m headed out for a bit but when I return I’ll try out your suggestion.

I’d love to know where to learn more of the conditional stuff so that it makes more sense to me. I’ve been developing for 30 years… maybe I’m not as good as I thought I was. :slight_smile:

So all of this is because I want a different version of my logo in my header based off of the time: after-hours, morning and afternoon.

My next condition will be to have the logo be something all-together if it’s a weekend. But I’ve seen a Cornerstone video that discusses this. Thanks to your direction and that video, I can probably make it all work.

Assuming the forum leaves this topic open long enough, I’ll put in my entire solution up (or maybe start a new thread with just the directions if the admins think that would be better) for others because I always seem to ask for help but I haven’t given back very much.

Glad to know that your question has been answered properly. Thanks to @tristup and @spedney. Unfortunately, there isn’t much documentation regarding this, aside from the one you posted above. There’s also a short video that you can watch anytime.

https://theme.co/docs/conditions-and-assignments

If you’re interested in creating your own conditions, check this out: https://theme.co/docs/conditions-api

Please don’t hesitate to reach out if you have more questions.

Have a nice day.

1 Like

Hey @ChadAustin,

Did you solve your issue regarding our concerns? If yes, that would be great.

Thank you.

Hi marc_a.

Actually no.

i pulled down my post that contained what I thought was a solution:

  • Morning Image (6 AM - 11:59 AM)
  • Variable: {{dc:global:time}}
  • Condition: After06:00
  • AND
  • Variable: {{dc:global:time}}
  • Condition: Before12:00
  • Afternoon Image (12 PM - 5:59 PM)
  • Variable: {{dc:global:time}}
  • Condition: After12:00
  • AND
  • Variable: {{dc:global:time}}
  • Condition: Before18:00
  • Night Image (6 PM - 5:59 AM)
  • Variable: {{dc:global:time}}
  • Condition 1: After18:00
  • OR
  • Condition 2: Before06:00

And it worked for a while… then I went to check on it a few hours later and it was no longer working.

I don’t get it.

Hi @ChadAustin,

I would suggest you use the format shown in the given screenshot.

If that does not help, please provide login credentials for your site in a secure note to examine it further, including:

– WordPress Site URL & Login URL
– WordPress Admin username/password
– Exact page URL and the section where you have added the condition.

To create a secure note, click the key icon underneath any of your posts.

NOTE: My timezone is GMT+0530, this might be different for your case.

Thanks

1 Like

Thanks for the offer Tristup! I might need that help later. when I try to have yet another image just for the weekend. Should I make that a new thread?

I found that my code example did work (I had to wait 24hrs to test my theory, though - lol)

The problem was the image that I wanted to only show for after hours (6pm to 9am the following day) didn’t like my conditional logic of 21:00 to 09:00.

The solution was to have two instances of the same image, but one for the time slot of 21:00 to 23:59, and the other from 00:00 to 09:00.

For those following, here’s the corrected conditional logic:

Morning Image (9 AM - 11:59 AM)

Variable: {{dc:global:time}}
Condition: After09:00
AND
Variable: {{dc:global:time}}
Condition: Before12:00

Afternoon Image (12 PM - 5:59 PM)

Variable: {{dc:global:time}}
Condition: After12:00
AND
Variable: {{dc:global:time}}
Condition: Before18:00

Night / After-hours Image 1 (6 PM - 23:59 PM)

Variable: {{dc:global:time}}
Condition 1: After18:00
AND
Condition 2: Before23:59

Night / After-hours Image 2 (12 AM - 8:59 AM)

Variable: {{dc:global:time}}
Condition 1: After00:00
AND
Condition 2: Before09:00

Hi @ChadAustin,

Glad to know that it is working now. If you want any help related to the weekend images, please create a new ticket.

Thanks