Displaying AdSense ads to visitors only in SMF
This 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 question that I assume was looking for a way to wrap ad code the same way I was wrapping the welcome message.
First, go and setup a new channel for your AdSense ads or just go to an existing channel and copy the Javascript code that you’re supposed to enter. Then it’s just a matter of inserting that code into the same PHP if construct that we did on the previous article.
-
if ($context[‘user’][‘is_guest’]==1)
-
{
-
echo ‘<script type="text/javascript"><!–
-
google_ad_client = "pub-xxxxxxxxxxxxxxxxxxxx";
-
google_ad_width = 728;
-
google_ad_height = 90;
-
google_ad_format = "728×90_as";
-
google_ad_type = "text_image";
-
google_ad_channel = "";
-
google_color_border = "FFFFFF";
-
google_color_bg = "FFFFFF";
-
google_color_link = "CC0000";
-
google_color_text = "000000";
-
google_color_url = "CC0000";
-
//–>
-
</script>
-
<script type="text/javascript"
-
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
-
</script>’;
-
}
One thing to pay attention to is that the variables inside the Javascript code will be different. Obviously line 4 needs to have your publisher id so that you get credit for the ads. And lines 5 through 14 differ depending on what ad format you show and what colors you use.
Question, Comments...
Do you have more questions. Please either leave a comment below or join us in our new forum.