Skip to content


Google adsense in MediaWiki

Here is how we set up Google Adsense to show in MediaWiki 1.12.0 and MediaWiki 1.13.0

1. Force the monobook skin for everyone (unless you want to edit every skin…)

2. In your skins folder, create a file within a subfolder (for instance “adsense/adsense_vertical.php”) with the following content (edit with your own Google Adsense code, also, make sure to choose a VERTICAL ad, since we are adding code in the left sidebar!):

<div id=”v-g-ads” class=”portlet”>
<h5>Google ads</h5>
<div class=”pBody”>
<script type=”text/javascript”><!–
google_ad_client = “pub-9471398824076666”;
/* 120×240 for ZenGamers sidebar */
google_ad_slot = “3512091103”;
google_ad_width = 120;
google_ad_height = 240;
//–>
</script>
<script type=”text/javascript”
src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”>
</script>
</div>
</div>

3. Edit MonoBook.php as follow:
After:

<?php foreach($this->data[‘language_urls’] as $langlink) { ?>
<li class=”<?php echo htmlspecialchars($langlink[‘class’])?>”><?php
?><a href=”<?php echo htmlspecialchars($langlink[‘href’]) ?>”><?php echo $langlink[‘text’] ?></a></li>
<?php } ?>
</ul>
</div>
</div>
<?php } ?>

Add:

<?php
if(!strstr($_SERVER[‘REQUEST_URI’], “Special:”) &&
!strstr($_SERVER[‘REQUEST_URI’], “action=submit”) &&
!strstr($_SERVER[‘REQUEST_URI’], “action=edit”) &&
!strstr($_SERVER[‘REQUEST_URI’], “Template:”)) {
include(“adsense/adsense_vertical.php”);
}
?>

4. Upload the stuff… and wait for Adsense to crawl your pages 😉

Credits: original post found there: http://forum.dreamhosters.com/3rdparty/29149-MediaWiki-and-Google-AdSense.htm

Posted in MediaWiki, web development.


2 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Sy Ali says

    Hey thanks a lot for this! It was _exactly_ what I needed to get going with my own ads.

  2. patheticcockroach says

    Of course that’s exactly what you needed for your wiki: that’s excatly what I did to my own one 😉



Some HTML is OK

or, reply to this post via trackback.

Please solve the CAPTCHA below in order to fight spamWordPress CAPTCHA