Hello,
Trying to figure how to do this but is there a way to have header ads not displayed on certain posts?
In general, I want to have the ad displayed for the majority of my post, but for the few, I’d like to not have them.
Please advise.
Thank you.
Hello crazydiver,
It is possible this thing if you are using a bit of CSS code to hide the header ad for certain posts, using the posts ID.
Below I gave you an example for a certain post which have this post ID -> postid-3050.
.postid-3050 .td-header-rec-wrap{
display:none;
}
The result you should see here -> http://screencast.com/t/HG8A7mv4
You will have to try the similar method for your side and see how it will work.
Thanks for your understanding!
Thanks!
Curious but do I have to implement this code each time for each post to avoid adsense?
Furthermore, just to be sure, which file should I implement the custom css code in?
Thank you Catalln.
Hi
Yes you will have to update the code for each post where you want to hide the ad. The code can be added in theme panel > custom code> custom css: http://screencast.com/t/fVCF9ObMfA
Thanks!
Thank you for the screenshots and explanation.
How do you do this for pages as well?
Thank you again!
Thank you Andrei! Very helpful!
Just one more question… how do you not have header ads appear in the 404 page?
Overall, the code you gave me for the pages work! Now I just want to disable the ad in the 404 page.
Thank you.
Hi,
If you want to remove the header ad from the 404 page, you can add a condition to the header ad code: https://codex.wordpress.org/Function_Reference/is_404 – http://screencast.com/t/axyi1FDMA
I hope this helps.
Thank you!
Hello Bogdan,
Where do I add the condition? Can’t I just add a css like how I did for the post and pages?
It seems that having adsense in pages like the 404 is against adsense TOS so asking a fix for this.
Please advise. Thank you.
-
This reply was modified 10 years by
crazydiver. Reason: additional clarification
Hi,
When using adsense it’s not recommended to hide the ad with css as the google crawler will still be able to detect the ad. It;s best to remove the ad from the code.
You can add the condition in the file I pointed out above like so:
if(!is_404()){
echo td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'header'));
}
?>
http://screencast.com/t/Wj8mA0Yo
Thank you!
Bogdan,
Thank you for bringing that up about Google crawlers on the css.
Thank you it worked out well!
Hello Bogdan,
This works for 404 pages on desktop and the responsive versions. How do I implement this for the mobile plugin theme?
Thank you again.
Btw, I have tried adding the custom css code to the custom code css in the mobile theme plugin but it doesn’t work.
Any ideas?
Hi,
The mobile theme uses different files than the desktop theme: http://screencast.com/t/Z3JgSlFJVg
Thank you!
Hello,
Thanks for the reply. To confirm, I add
if(!is_404()){
echo td_global_blocks::get_instance('td_block_ad_box')->render(array('spot_id' => 'header'));
}
?>
anywhere into the 404.php to prevent ads appearing in the 404 page for the mobile plugin theme?
Thanks.
Hi,
The mobile ad code is located in header.php from the mobile file. Please edit this code and add the condition to it like so:
http://screencast.com/t/WPjEQjbIzZCC
use this code for mobile:
<?php
// ad under header
if(!is_404()){
echo td_global_blocks::get_instance('td_block_ad_box_mob')->render(array('spot_id' => 'header_mob'));
}
?>
Thank you!
Hello Bogdan,
The ads do not go away when applying the code. Additionally, it adds another ad on the header for all other pages.
Please advise. I think you meant 404.php and not header.php
-
This reply was modified 10 years by
crazydiver.
@crazydiver
Glad you got it working 🙂 Best of luck on your project!
@indeepblue
Please make sure you follow the steps correctly from the above solution and clear any at all caching. If it still does not work please open a new topic and specify exactly what you want to achieve and the steps you took in this regasrd with an example of how you implemented the code.
Thank you!
