Extension:Google AdSense

From MediaWiki.org
(Redirected from Extension:Google AdSense 2)
Jump to navigation Jump to search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.svg
Google AdSense

Release status:Extension status unmaintained

ImplementationTemplate:Extension#type Skin
DescriptionTemplate:Extension#description Allows to add Google AdSense to the sidebar
Author(s)Template:Extension#username Siebrand Mazeland (Siebrandtalk)
Latest versionTemplate:Extension#version 2.2.0 (2015-06-14)
MediaWikiTemplate:Extension#mediawiki 1.23.x - 1.30.x
PHPTemplate:Extension#php 5.3.x - 5.6.x
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license MIT License
* $wgGoogleAdSenseClient
  • $wgGoogleAdSenseSlot
  • $wgGoogleAdSenseID
  • $wgGoogleAdSenseWidth
  • $wgGoogleAdSenseHeight
  • $wgGoogleAdSenseSrc
  • $wgGoogleAdSenseAnonOnly
Hooks usedTemplate:Extension#hook

Translate the Google AdSense extension if it is available at translatewiki.net

Check usage and version matrix.

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:
    require_once "$IP/extensions/GoogleAdSense/GoogleAdSense.php";
    // Replace this with your own publisher ID (google_ad_client / data-ad-client)
    $wgGoogleAdSenseClient = 'none'; // Client ID for your AdSense script (example: ca-pub-1234546403419693)
    // Replace this with your AdSense ad unit ID (google_ad_slot / data-ad-slot)
    $wgGoogleAdSenseSlot   = 'none'; // Slot ID for your AdSense script (example: 1234580893)

(You can get your publisher ID and ad unit ID from the "Get code" page: Get and copy the ad code.)

  • Add any of the optional settings below - if your settings deviate from the defaults:
// Width of the AdSense unit, specified in your AdSense account (google_ad_width / data-ad-width)
$wgGoogleAdSenseWidth = 120;

// Height of the AdSense unit, specified in your AdSense account (google_ad_height / data-ad-height)
$wgGoogleAdSenseHeight = 240;

// Source URL of the AdSense script. No need to change - it can't deviate from the defaults.
$wgGoogleAdSenseSrc = '//pagead2.googlesyndication.com/pagead/show_ads.js';

// Show the AdSense box only for anonymous users: true or false. Default is false.
$wgGoogleAdSenseAnonOnly = false;

// This can be anything you like. Default is 'none'.
$wgGoogleAdSenseID = 'none';
  • 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[1].
  • Remember to disable ad-blocking services such as AdBlock when you want to see if the extension is working!
  • YesY Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

See also[edit]


  1. Placing ads under a misleading header, AdSense Help: Ad placement policies.