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 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
- Go to Plugins -> Editor in the WordPress dashboard.
- Select Google AdSense in the Select plugin to edit: menu at the top, and click Select.
- From the list of files on the right, click to open the file called google-publisher/Admin.php.
- 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'); }
- Click Update File to save your edits.
- Return to the WordPress post editor and check the box next to Disable ads on this page.
- 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)
i hope it does cause i'm about to try it on my blog post
This doesn't work
This worked perfectly. Thanks a lot for the simple precise instructions.
Thanks very much David, this was really helpful for me!
David Lynch Where on the post edit page does the Adsense Plugin option come up? I can't find it :(
Interesting. It worked for me.
Or-more Moje I haven't yet. All the other search results that came up were just other people seeking an answer, usually via Google's own forums.
Were you able to find something that works? I'm trying to disable ads on a post.
You're very welcome, Elisabeth! I wasn't positive that anyone would ever read this article, but your comment makes it worth the effort.