Usually we need to hide AdSense unit for policy compliance or for control of keywords to AdWord users. Here is how to hide AdSense units on selected WordPress post. There is CSS, PHP, Javascript or simply ready to use WordPress Plugin to do it. Previously we actually talked about some solutions for 404 pages like pages. We will link those old mentioned ways under proper sub-headers in this guide. We are taking it granted that user is using responsive Ad units.
![How To Hide AdSense Units On Selected WordPress Post](https://thecustomizewindows.cachefly.net/wp-content/uploads/2017/07/How-To-Hide-AdSense-Units-On-Selected-WordPress-Post.png)
How To Hide AdSense Units On Selected WordPress Post : Using WordPress Plugin
Once we touted free Ad Injection as best AdSense plugin. If you are injecting AdSense units via Ad Injection’s main page or widgets, you can easily block AdSense to get injected by using option provided by Ad Injection. There is way to add Comma post or page IDs like 267, 838, 1243 and select option as “Never Show in”. 5 minutes matter. You can also set a custom tag or category and restrict. This method works for traditional and responsive Ads.
How To Hide AdSense Units On Selected WordPress Post : Using CSS
Most useful and highly effective in difficult situations. This works only for responsive Ads. Normally standard WordPress themes like StudioPress Genesis has way to inject scripts on header, body etc on particular post from WordPress post editing page. You’ll get documentation for “Hiding an ad unit” by Google AdSense :
---
1 | https://support.google.com/adsense/answer/6307124 |
You need to have similar setup for showing Ads on your website. If your targeted Ad unit’s class is adslot_1
then if you inject this kind of CSS on particular post from WordPress post editing page, Ad unit will get collapsed :
1 2 3 4 | <style type="text/css"> @media (max-width: 1500px) { .adslot_1 { display: none !important; } } @media (min-width:500px) { .adslot_1 { display: none !important; } } </style> |
It is not illegal as long you are doing for not violating policy. If you have sexy booby girl’s photographs on a post, you can use this. AdSense has prohibited contents. If your whole site has such contents of course it is not eligible for using AdSense, but odd 1-2 conflicting situation can arise :
1 | https://support.google.com/adsense/answer/1348688?hl=en |
How To Hide AdSense Units On Selected WordPress Post : Using PHP
We talked about hiding AdSense units on WordPress 404 pages and different AdSense units for mobile and desktop. They are based on similar logic and both linked articles are important to read if you are not used with such. We will need to programmatically determine when in this specific post ID 2 the logic is passed :
1 2 3 4 | if (is_single("15")) { //Do in intended post whose ID is 15 } |
Exactly like 404 page’s logic, say NO to post whose ID is 15 :
1 2 3 | <?php if ( ! is_single("15") ) : ?> // Adsense code here <?php endif; ?> |
Here is function reference :
1 | https://developer.wordpress.org/reference/functions/is_single/ |
How To Hide AdSense Units On Selected WordPress Post : Using Javascript
You should email to AdSense account manager.
Tagged With Google