CentOS 7.x Configure mediawiki to display google adsense advertizements
Home > CentOS > CentOS 7.x > Web Based Tools > Mediawiki > CentOS 7.x Configure mediawiki to display google adsense advertizements
Enable auto-ads using HeadScript extension
Google has created auto-ads which require putting only one JS script between head and /head elements. That can be done via Headscript extension ( https://www.mediawiki.org/wiki/Extension:HeadScript ) which is very straightforward (Single PHP file) to setup and use.
On local machine this usage led to undefined variable type warning. So commenting entire $wgExtensionCredits[$type][] variable with php /* */ comments seems to have solved the problem.
Debug ads not getting displayed issue
For ads to get displayed the site need to go through:
- Review - https://support.google.com/adsense/thread/24997874?hl=en
- Then ads.txt for approved site needs to be placed in document_root
- Then auto ads need to be enable for site using google.com/adsense
Each of these steps might take a few days for google to complete from their side. Once all three steps are done, the ads should get displayed and there might be corresponding revenue also.
- Create Google Adsense Account
- Optionally, Link adsense account to youtube channel
- Create appropriate ad unit for displaying ads on mediawiki and get script code.
- Paste script code in Localsettings.php file to display google adsense in mediawiki
Header advertizement script
$wgHooks['SiteNoticeAfter'][] = function(&$siteNotice, $skin) { $siteNotice .= <<< EOT <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- XXX --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-xxxxxx" data-ad-slot="xxxxxx" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> EOT; return true; };
Remember to replace script in above code with script available in your google adsense account related to the ad
$wgHooks['SkinAfterContent'][] = function(&$data, $skin) { global $myAdCode; $data .= '<div style="text-align:center;">'; $data .= <<< EOT <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- XXX --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-xxxxx" data-ad-slot="xxxxx" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> EOT; $data .= '</div>'; return true; };
Remember to replace script in above code with script available in your google adsense account related to the ad
Refer:
Setup mediawiki adsense extension
Latest extension updated for mediawiki 1.31+. However due to missing extension.json file it does not works
- Create account on www.google.com/adsense It might take 1 or 2 days for account to be activated
- After activation go to Ads -> Ad units and create a new "Ad unit". Copy the script code displayed at end for valuable parameters required later.
- Download mediawiki Adsense extension from https://www.mediawiki.org/wiki/Extension:Google_AdSense
- Extract downloaded extension files in ./extensions/ folder inside mediawiki source base folder
- Add following to localsettings.php
- require_once "$IP/extensions/GoogleAdSense/GoogleAdSense.php";
- $wgGoogleAdSenseClient = 'none'; // Client ID for your AdSense script (example: ca-pub-1234546403419693)
- $wgGoogleAdSenseSlot = 'none'; // Slot ID for your AdSense script (example: 1234580893)
- $wgGoogleAdSenseID = 'none'; //Name of ad unit created above. This would be part of Adsense script comment
- $wgGoogleAdSenseSrc = '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'; //This is part of script
- Reload mediawiki and test. There should be "Advertizements" under tools on the left side.
Home > CentOS > CentOS 7.x > Web Based Tools > Mediawiki > CentOS 7.x Configure mediawiki to display google adsense advertizements