开发者

Can I wrap Adsense code in PHP to omit adsense from specific webpages?

I am using an instance of mediawiki and have added adsense to the php file of the skin. This places the adsense banner on all pages but I would like to omit the adsense banner from very specific pages.Primarily the "homepage" (but keep adsense on all the other pages). My site is really big so going in the other direction (adding adsense to specific pages) would be a huge pai开发者_StackOverflow中文版n.

I was hoping there was a bit of PHP code I could wrap the adsense code in that would allow me to specify URLS for the adsense to ignore.

Thank you.


I'm not a programmer so I have no idea what you just said.

However, This article answered my question:

http://forum.dreamhosters.com/3rdparty/29149-MediaWiki-and-Google-AdSense.htm

I just added the "Main Page" (homepage) to the list of omitted pages in the list.

Example:

!strstr($_SERVER['REQUEST_URI'], "Main_Page") &&

THanks anyway.


Make an array of the pages to omit, then check the server environment variable REQUEST_URI to see if it's in the array?

If strstr works OK for you, fine. The way I mentioned would probably be coded:


!(in_array($_SERVER['REQUEST_URI'], array("/Main_page", "/some/other/page", "/no_ads.html")) &&

I rarely use PHP any more, otherwise I would have provided code at the time. I just get onto stackoverflow when I run into snags in my own coding, and try to offer hints when I can. Sometimes they help, sometimes they don't.


You can just use the AdSense extension and hide the ads on specific pages with custom CSS.

Or you can use a specific AdSense extension which already hides the ads where you want, namely the main page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜