Google Adsense MediaWiki Extension

From Tech Wiki
Revision as of 13:47, 30 April 2016 by Adam.birds (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The Google AdSense extension allows to easily add Google AdSense advertisements to the sidebar of your wiki. This extension requires an account with Google's AdSense.


  • Download and place the file(s) in a directory called GoogleAdSense in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
require_once "$IP/extensions/GoogleAdSense/GoogleAdSense.php";
// Your Publisher ID
$wgGoogleAdSenseClient = 'pub-8330046405419293';
// Your AdSense AD Unit ID
$wgGoogleAdSenseSlot = '1640430293';
// This can be anything you like
$wgGoogleAdSenseID = 'yourwiki-2';
  • Add any of the optional settings below, if your settings deviate from the defaults:
// Width of the AdSense box, specified in your AdSense account
$wgGoogleAdSenseWidth = 120;
// Height of the AdSense box, specified in your AdSense account
$wgGoogleAdSenseHeight = 240;
// Source URL of the AdSense script
$wgGoogleAdSenseSrc = "";
// Show the AdSense box only for anonymous users
$wgGoogleAdSenseAnonOnly = true;
// Your Publisher ID
$wgGoogleAdSenseClient = 'replace this with the client name';
// Your Adsense Ad Unit ID
$wgGoogleAdSenseSlot = 'replace this with the slot name';
//This can be anything you like
$wgGoogleAdSenseID = 'replace this with your ID';
  • If you want to add a "Text/image, 200x200" into the Vector skin you will need to shift the left panel over slightly. Add the following to the MediaWiki:Vector.css page
#footer {
    margin-left: 11em;
#left-navigation {
    left: 11em;
  • The default portlet label "Advertisements" can be changed to "Sponsored Links" on the "MediaWiki:Googleadsense" page. Please note: no other variations are permitted.
  • Remember to disable ad-blocking services such as AdBlock when you want to see if the extension is working!