Featured image of post How to Integrate Google AdSense with WordPress

How to Integrate Google AdSense with WordPress

Discover a simple method to integrate Google AdSense into your WordPress website and optimize its configuration for enhanced utilization, management, and outcomes.

This guide will demonstrate:

  • Verifying your website within your AdSense account.
  • Activating Site Authorization to prevent misuse of your AdSense code by unauthorized websites.
  • Implementing automatic placement of AdSense ads for mobile and desktop visitors (known as Page-level ads).
  • Testing AdSense Page-level ads.

Before proceeding, ensure you possess an approved AdSense account and have incorporated the necessary Privacy and Cookie Policy information on your website, adhering to Google AdSense policies.

Initially, let’s verify your website, a mandatory step for utilizing the QuickStart functionality. QuickStart facilitates automatic and intelligent placement of AdSense ads for both mobile and desktop users visiting your website.

  1. Access your Google AdSense account, navigate to Settings, and select My Sites.
  2. Click the Plus button.
  3. Enter your website address in the provided field.
  4. Choose Add Site to enable Google AdSense on your WordPress site.

At this juncture, consider configuring your settings to restrict AdSense display exclusively to your authorized websites.

Occasionally, external websites might scrape the content your website content, including your AdSense code, and incorporate it into their own sites.

Should this occur, and the infringing website violates Google Ads policies, it is you who could face repercussions. This precautionary measure ensures you won’t regret neglecting it in the future.

Implementing Site AdSense Authorization: Adding Google AdSense to WordPress

  1. Within the Manage Sites section, click the three stacked dots on the right located on the page’s side.
  2. Select Site Authorization.
  3. Enable the feature and save your changes.

Now, let’s activate automatic ad placement on your website.

Enabling Automatic Ad Placement:

  1. In your AdSense account, go to My Ads and select Page-level Ads.
  2. Activate either Anchor/overlay ads, Vignette ads, or both by toggling the sliders.
  3. Open your WordPress Dashboard in a new browser tab or window.
AdSense account, go to My Ads, then Page-level Ads

Next, obtain the necessary code for your website to finalize the setup.

It’s important to note that this code is identical to the one required from new Google Ads users during the application process. Therefore, you might already have it implemented and can proceed directly to the Testing section.

However, long-time users of Google Ads did not need to place this code during their application, necessitating these steps.

Furthermore, it’s noteworthy that this specific code can be universally applied to all pages across your websites.

For the subsequent step, we’ll create a basic plugin to embed the AdSense code on every page of your WordPress website.

Utilizing the Pluginception plugin provides a remarkably swift and straightforward plugin setup, so let’s install it first.

Installing Pluginception:

  1. Within your WordPress Dashboard, navigate to Plugins and select Add New.
  2. Enter Pluginception in the search bar.
  3. Click Install Now.
  4. Click Activate. This will introduce a new option called “Create a New Plugin” within the Plugins menu.

Creating Your Custom Plugin:

  1. Click the “Create a New Plugin” link.
  2. Assign a name to your plugin, such as “My Google AdSense Placement Plugin.”
  3. Select the “Create a Blank Plugin” button.
  4. Insert the code provided in the video tutorial or below these steps if you’re following the written instructions, into your plugin.
  5. Return to the “Add Google AdSense to WordPress” section.
  6. Click the Get Code button.
  7. Copy the code to your clipboard.
  8. Replace the “YOUR ADSENSE CODE” placeholder with the code copied from AdSense in the previous step.
  9. Finally, click the “Update File” button.

There are two methods to test your implementation. Let’s perform both now.

  1. Access your website from your desktop or laptop computer.
  2. Right-click anywhere on the page and select “View Source.”
  3. Search for the code you inserted. You can typically use the “Find” function (Ctrl+F) and enter “adsbygoogle” as one word without spaces.
  4. Now, let’s verify ad display on mobile devices. Open a page on your website using a high-end mobile device in portrait orientation (instead of landscape). Append “#googleads” to the end of the URL.
  5. Choose the ad format you wish to test and observe the results on your device.
  6. For vignettes, click any highlighted link on your page to confirm ad functionality.

If you encounter issues with ad display during testing, consult Google’s “Guide to testing Page-level ads” for potential explanations. Perform a Google search for “Guide to testing Page-level ads” to locate the relevant page.

Code Snippet Used in this Tutorial: Adding 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 nexus-security WordPress themes provide a designated area within their theme options for easy code upload if you prefer an alternative approach, although both methods will yield identical results.

Licensed under CC BY-NC-SA 4.0