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.

PHP:
  1. if ($context[‘user’][‘is_guest’]==1)
  2. {
  3. echo ‘<script type="text/javascript"><!–
  4. google_ad_client = "pub-xxxxxxxxxxxxxxxxxxxx";
  5. google_ad_width = 728;
  6. google_ad_height = 90;
  7. google_ad_format = "728×90_as";
  8. google_ad_type = "text_image";
  9. google_ad_channel = "";
  10. google_color_border = "FFFFFF";
  11. google_color_bg = "FFFFFF";
  12. google_color_link = "CC0000";
  13. google_color_text = "000000";
  14. google_color_url = "CC0000";
  15. //–>
  16. </script>
  17. <script type="text/javascript"
  18.   src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
  19. </script>’;
  20. }

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.

Leave a Reply