How to Add AdSense to WordPress

In this tutorial, you will learn:

  • How to verify your web site in your AdSense account.
  • How to activate Site Authorization to prevent abuse of your AdSense code by sites that don’t belong to you.
  • How to add automatic placement of AdSense ads for mobile and desktop visitors (called Page-level ads).
  • How to test AdSense Page-level ads.

To follow along, please be certain that you have an approved AdSense account, and that you have the proper Privacy and Cookie Policy information in place on your web site, as per the Google AdSense policies.

First, let’s verify your site. This is a required step if wanting to use the QuickStart feature. QuickStart allows for the automatic, intelligent, placement of AdSense ads for mobile and desktop visitors to your web site.

  1. To verify your web site, within your Google AdSense account, click on Settings, then click My Sites.
  2. Click the Plus button.
  3. Type in your web site address in the box.
  4. Click Add Site.

At this point you may want to set it up so that *only* your authorized sites can display your AdSense.

Sometimes what happens is, another site will scrape the content of your web site, including your AdSense code, and then add that content to their site.

If that happens, and that site violates any AdSense policies, it’s you that can be affected by it. This step just prevents you from wishing you had done it sooner, if down the line something like this happens.

To setup Site Authorization:

  1. In the Manage Sites area, click the 3 stacked dots on the right side of the page.
  2. Click on Site Authorization.
  3. Turn it on, and click Save.

Now, let’s activate the auto-placement of ads on your web site.

To turn on this feature:

  1. In your AdSense account, go to My Ads, then Page-level Ads.
  2. Turn on one or both of Anchor/overlay ads and Vignette ads, by sliding the sliders.
  3. Open your WordPress Dashboard in a new Tab or Window.

The next step is to get the needed code for your web site to finalize the setup.

Worth noting though, that this code is the same code that newer AdSense users would have needed to add to their web sites during the application process. So, you may already have it in place, and can skip to the Testing section.

Long time users of AdSense did not need to place this code when applying, so these steps will be required.

Also, worth mentioning, is that this exact same code can be used on all pages of all your sites.

For this next step we are going to create a quick plugin to place the AdSense code on all pages of your WordPress web site.

I find that it’s extremely easy and fast to setup a plugin using the Pluginception plugin, so let’s get that installed first.

To install Pluginception, follow these steps:

  1. From within your WordPress Dashboard, click on Plugins, then click Add New.
  2. In the search box, type Pluginception.
  3. Click Install Now.
  4. Click Activate. This will open up a new option within the Plugins menu called Create a New Plugin.

Follow these steps to create your custom plugin:

  1. Click the Create a New Plugin link.
  2. Give the plugin a name such as My Google AdSense Placement Plugin.
  3. Click the Create a Blank Plugin button.
  4. Now, add the code into your plugin that you see in the video, or below these steps if you are following along within the written tutorial.
  5. Switch back to AdSense.
  6. Click the Get Code button.
  7. Copy the code to the Clipboard.
  8. Replace where it says YOUR ADSENSE CODE with the code copied from AdSense in the previous step.
  9. Click the Update File button.

There are two ways to test your work. Let’s do both right now.

  1. Visit your web site from your Desktop or Laptop computer.
  2. Right-click anywhere on the page and click View Source.
  3. Look for the code that you inserted. You can do a find, usually by pressing Ctrl+F and typing adsbygoogle as one word with no spaces.
  4. Now, let’s have a look to see if the ads show in Mobile. Open up a page on your web site with a high-end mobile device in Portrait view (as opposed to Landscape view). Add #googleads to the end of the URL.
  5. Select the ad format that you want to test, then check the results on your device.
  6. For vignettes, click any of the highlighted links on your page to test the ads are working.

If you are having problems displaying ads during testing, be sure to visit Google’s Guide to testing Page-level ads to see why that may be. Do a Google search for “Guide to testing Page-level ads” to find the page.

Code used within this tutorial:

function my_google_adsense_placement_function() {
  $output='YOUR ADSENSE CODE';
  echo $output;

Alternative Option for Adding Adsense

You can also use the simple adsense insertion plugin to add Google Adsense to your site.

Source: Web Developments