Show 'Goodevening' at specific times?

Hey there everyone! Thanks in advance for the help.

I would like to greet the visitors of my website with a ‘Goodmorning’ or ‘Goodevening’ (or something else) text. I know i need some custom code for that, but I have no idea where to start - I’m a designer, not a developer. So who can help me out? :slight_smile:

Would love to learn something on the way, so just a nudge in the right direction would be great!

Here is something that might help.

Place a text element where you would like the greeting to show.
Give it a ID name of “lblGreetings”, in the settings panel.

Place this code in the page setting (Before body tag).

<script>
var myDate = new Date();
var hrs = myDate.getHours();

var greet;

if (hrs < 12)
    greet = 'Good Morning';
else if (hrs >= 12 && hrs <= 17)
    greet = 'Good Afternoon';
else if (hrs >= 17 && hrs <= 24)
    greet = 'Good Evening';

document.getElementById('lblGreetings').innerHTML = greet;</script>

You’re all done :slight_smile:

(You’ll see the results only in the published site)

3 Likes

Thank you @Eli11, – it worked perfectly! :pray: