MyBB Community Forums

Full Version: Simple Greeting Message to visitors
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Please note that this tutorial assumes that you know a very small amount of JavaScript. It's targeted towards beginners, since more advanced JavaScript coders could probably whip this out in a minute. Wink

This code is really simple - in the Header, if the user is visiting in the morning, a message saying "Good Morning!" will be shown, and if they are visiting in the afternoon/evening, a message saying "Good Afternoon!" will be displayed. This all refers to their timezone, not anything set by the board.

Okay. First you need to go to ACP>Templates and Style>Templates>Template Name>Header Templates>Header.

Now, you can add this script almost anywhere here, but as always, give thought to the style of your forum. I have an Apart style installed, and I have this message next to the "Search" button where it blends in nicely.

Now, add this code anywhere, but remember it will show up wherever you add it:
<p id="mywelcomemessage"></p>

<script type="text/javascript"><!--
var d = new Date();
var time = d.getHours();

if (time > 12) 
  document.getElementById("mywelcomemessage").innerHTML="<strong>Good Afternoon!</strong>";
  document.getElementById("mywelcomemessage").innerHTML="<strong>Good Morning!</strong>";

It's that easy! You now have a dynamic greeting that will respond to the user's clock, instead of responding to the board timezone.

I hope this helps you. Smile

Updated 26/09/12
The good thing about this plugin is it rely on the user's time zone. I think i might use this. Thanks.
Anyway do you know how to display the IP address of users whether guest or registered.
Something like this.
[Image: welcomeip.png]

It appear on the index.php upon visiting the site. Thanks.
Not working for me. It always says "Good Morning" Sad

OK, thats a keyword conflict, I think.

Replaced 'var time' with 'var n' and it worked Smile
I've updated this. Previously the code might've caused your entire forum to vanish, depending on where it was put. Now that risk is gone. Plus I used updated HTML - <strong> instead of <b>.