How to Add Google AdSense to WordPress

Learn how to add the google AdSense on your WordPress website in an easy way and fully set it up for a better usage, control and results.

Updated on July 25, 2022
How to Add Google AdSense to WordPress

Learn how to add Google AdSense to your WordPress website in an easy way and fully set it up for better usage, control, and results.

In this tutorial, you will learn:

  • How to verify your website 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 website, 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 website.

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

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

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

If that happens, and that site violates any google ads 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 set up Site AdSense Authorization: Add Google AdSense to WordPress

  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 website.

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 the Anchor/overlay ads and Vignette ads, by sliding the sliders.
  3. Open your WordPress Dashboard in a new Tab or Window.
AdSense account, go to My Ads, then Page-level Ads

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

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

Long-time users of google ads 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 website.

I find that it’s extremely easy and fast to set up 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. Firstly, click the Create a New Plugin link.
  2. Secondly, live 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 with the written tutorial.
  5. Switch back to add Google AdSense to WordPress.
  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. Finally, click the Update File button.

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

  1. Firstly, visit your website from your Desktop or Laptop computer.
  2. Secondly, 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 on Mobile. Open up a page on your website 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. Finally, for vignettes, click any of the highlighted links on your page to test whether 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: Add Google AdSense to WordPress

function my_google_adsense_placement_function() {
  $output='YOUR ADSENSE CODE';
  echo $output;
}
add_action('wp_head','my_google_adsense_placement_function');

All the Visualmodo WordPress themes have a custom area for an easy code upload on their theme options in case you want to do it in another way however both ways will work perfectly.