How to create a welcome message for SMF

If you’ve spent much time on forums you’ve no doubt noticed that many forums will display a message to guests welcoming them and often displaying a link to the registration page. Not having found a simple solution to do this in my two Simple Machines Forums I looked at the code to see if it was something that could be done easily.

Fortunately it is very easy. Each page in SMF has a variable available called $context which contains information on the board and the current user. One of the array members in the $context variable is $context['user']['is_guest'] which is 1 for a visitor that isn’t logged in. This makes it really easy to display a message only to visitors.

Where ever you decide you want the welcome message to appear just place the following code.

PHP:
  1. if ($context[‘user’][‘is_guest’]==1)
  2. {
  3. echo ‘Welcome Visitor’;
  4. }

Of course you can replace Welcome Visitor with whatever you want to say, and can include HTML tags if you want. For the forum that I did this on I wrapped the welcome message in a div tag so that the message is bordered.

If you want to see what this looks like I’m using this code on my PhotoArtsForum.com photography forum. You’ll see a welcome message when you visit for the first time, but after you register that message will not display.

Since you can display HTML or Javascript code, or run PHP code, it would be pretty easy to include advertising only to guest visitors. It would just be a matter of wrapping the ad display code in the if construct above.

Question, Comments...

Do you have more questions. Please either leave a comment below or join us in our new forum.

3 Responses to “How to create a welcome message for SMF”

  1. Can you put the code with the wrap, please?

  2. I guess you’re asking about wrapping the ad code, correct?

    In line 3 above where it now says echo ‘Welcome Visitor’;, just replace that with whatever ad code you want. If you’re using AdSense code you’ll need to either drop out of PHP parsing (?> before the AdSense and

  3. [...] is a spin off of a previous post that I did on displaying a message to guests on a Simple Machines forum. A commenter asked a [...]

Leave a Reply