X

How To Disable Ads On Posts: Google AdSense Plugin For WordPress

    Categories: WordPress

Despite mixed reviews, I’m a fan of the official Google AdSense Plugin for WordPress because it’s easy to set up, works beautifully on mobile devices, and seems to generate more revenue than ad units I place myself. Best of all, it’s a huge timesaver—and I’ve spent a lot of time tweaking ad layouts in the past. In this article, I’ll show you how to enable the AdSense Plugin meta box so you can disable ads on single posts.

I recently launched a new section of this website with posts that I don’t want to have ads, but when I went to disable the ads on those specific posts, I noticed something strange: Even though there was a AdSense Plugin meta box with a “Disable ads on this page” checkbox in the WordPress Pages editor, there was no AdSense Plugin meta box in the Posts editor.

I Googled the problem and didn’t find anything but frustrated users, but I figured that if you could disable AdSense for individual pages, the functionality must already be built in. The solution is as simple as changing a single line of code. We’ll enable the AdSense plugin meta box for pages and posts, so you can disable ads on single posts in WordPress. 

How To Disable Ads On Single WordPress Posts With The Google AdSense Plugin

  1. Go to Plugins -> Editor in the WordPress dashboard.
  2. Select Google AdSense in the Select plugin to edit: menu at the top, and click Select.
  3. From the list of files on the right, click to open the file called google-publisher/Admin.php.
  4. Change ‘page’ to array(‘page’, ‘post’) in this section of code, so this:
     public function addPageEditOptions() {
        add_meta_box('googlePublisherPluginMetaBox',
            __('AdSense Plugin', 'google-publisher-plugin'),
            array($this, 'showPageEditOptions'), 'page', 'side', 'low');
      }

    becomes this:

     public function addPageEditOptions() {
        add_meta_box('googlePublisherPluginMetaBox',
            __('AdSense Plugin', 'google-publisher-plugin'),
            array($this, 'showPageEditOptions'), array('page', 'post'), 'side', 'low');
      }

  5. Click Update File to save your edits.
  6. Return to the WordPress post editor and check the box next to Disable ads on this page.
  7. Update or Publish the post with no ads.

That’s right: We fixed the problem by changing a single line of code!

Wrapping It Up

By this point, you’ve successfully added the AdSense Plugin meta box to the WordPress editor and you can disable ads on the posts you choose. Writing good articles is all about user experience, and users don’t like seeing ads—so when I need to turn them off, it’s a win-win for me and for my readers.

Thanks for reading, and remember to Payette Forward,
David P.

View Comments (9)

David Payette: I'm a former Apple employee and the founder of Payette Forward, and I'm here to help you with your iPhone.