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 type=”text/javascript”

3. Edit MonoBook.php as follow:

<?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 } ?>
<?php } ?>


if(!strstr($_SERVER[‘REQUEST_URI’], “Special:”) &&
!strstr($_SERVER[‘REQUEST_URI’], “action=submit”) &&
!strstr($_SERVER[‘REQUEST_URI’], “action=edit”) &&
!strstr($_SERVER[‘REQUEST_URI’], “Template:”)) {

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

Credits: original post found there:

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.

Sorry about the CAPTCHA that requires JS. If you really don't want to enable JS and still want to comment, you can send me your comment via e-mail and I'll post it for you.

Please solve the CAPTCHA below in order to fight spamWordPress CAPTCHA