Topic on Extension talk:Google AdSense

How to make GoogleAdsense 2 display ads on content pages only

7
87.163.99.34 (talkcontribs)

Thanks for the Google AdSense 2 extension, it works great! However, I have a question you may have an answer to:

I would like ads to be shown only on pages in the NS_MAIN namespace. Can this be done in GoogleAdSense.php or in LocalSettings.php? If so, how?

According to Google's current AdSense Terms and Conditions ads should not display on non-content pages, which does not necessarily include various system or even search pages etc. If they are, the publisher may risk having their account terminated.... I guess this was something that Google introduced after you originally wrote the extension.

Thanks in advance for any advise!

Siebrand (talkcontribs)

There are no limitation options in the extension at the moment. What you can do is use robots.txt to block them from spidering parts of your wiki, and consequently, no ads will be placed on pages where the spider is blocked.

Alternatively, you can consider creating a patch that will only add the portlet on pages in $wgContentNamespaces.

87.163.106.94 (talkcontribs)

Thanks for the tips. However, modifying robots.txt for this particular purpose alone sounds to me a less than an ideal solution. I'm not quire sure how to create a patch. However, adding the following in GoogleAdSense.class.php this seems to do the trick:

global $wgTitle;
                if ($wgTitle->getNamespace() != 0) {

                return $bar;
}
75.68.197.26 (talkcontribs)

Does anyone know what the best way to achieve this would be now that $wgTitle has been deprecated in 1.19?

FloydlawsonMB (talkcontribs)

I was able to use the following in GoogleAdSense.class.php to replace $wgTitle:

	// Keeps blank pages from showing AdSense
       if ( $skin->getTitle()->getNamespace() != 0) {
           return $bar;
		}

I hope that helps.

This post was posted by FloydlawsonMB, but signed as Floydlawson.

In Correct (talkcontribs)

HELP!! I do not know where to enter these codes. I have tried BOTH of them. Am I entering them in the wrong location in the GoogleAdsense.class.php file?! I am STILL getting ads on non content pages. What a dumb extension. It should ALREADY be able to display ads on the main article pages. Instead, it displays ads on ALL of them. This includes talk pages and history pages.

Zimbres (talkcontribs)

I read about this function and I think it could imput the Adsense in the body of the article. =========================


 <?php
 $wgExtensionFunctions[] = "wfassExtension";
 function wfassExtension() {
 global $wgParser;
 $wgParser->setHook( "adsensesearch", "renderass" );
 }
 function renderass( $input, $argv ) {
 $output = '
 <script type=\"text/javascript\"><!--
 google_ad_client = \"xxxxxxxxxxxxxx\";
 google_ad_width = 728;
 google_ad_height = 90;
 google_ad_format = \"728x90_as\";
 google_ad_type = \"text_image\";
 google_ad_channel =\"\";
 google_color_border = \"F7DBBC\";
 google_color_bg = \"F7DBBC\";
 google_color_link = \"60442D\";
 google_color_url = \"60442D\";
 google_color_text = \"60442D\";
 //--></script>
 <script type=\"text/javascript\"
 src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">
 </script>
 ';
 return $output;
 }
 ?>
 

Anyone has any idea how to improve it?

Reply to "How to make GoogleAdsense 2 display ads on content pages only"