admin管理员组文章数量:1434014
Set-up
I have the following standard Adsense script inserted in my header.php
file,
<script async src="//pagead2.googlesyndication/pagead/js/adsbygoogle.js">
</script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-********",
enable_page_level_ads: true
});
</script>
This allows me to display ads on all pages instantly without too much hassle.
Problem
I'd like to prevent display of all adsense ads on specific pages of my website.
I'm looking for some 'if' function to stop the display. Anyone knows of such a function?
Set-up
I have the following standard Adsense script inserted in my header.php
file,
<script async src="//pagead2.googlesyndication/pagead/js/adsbygoogle.js">
</script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-********",
enable_page_level_ads: true
});
</script>
This allows me to display ads on all pages instantly without too much hassle.
Problem
I'd like to prevent display of all adsense ads on specific pages of my website.
I'm looking for some 'if' function to stop the display. Anyone knows of such a function?
Share Improve this question asked Jul 13, 2017 at 8:52 LucSpanLucSpan 1131 silver badge5 bronze badges 4 |3 Answers
Reset to default 2You can use this function:
<?php if(is_page('your-page-slug')): ?>
//do nothing on selected pages
<?php else: ?>
<script async src="//pagead2.googlesyndication/pagead/js/adsbygoogle.js" />
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-********",
enable_page_level_ads: true
});
</script>
<?php endif; ?>
If you want to disable this on more than one page, just add them like this:
<?php if(is_page('your-page-slug1') || is_page('your-page-slug2')): ?>
Wordpress Developer Resources are very useful (more than codex), so i recommend checking them out first if you don't know how to do something
Step 1: Login to your your AdSense dashboard and click on My ads>>Auto ads>>New URL group
Step 2: Select URLs The next thing you need to do is to enter all the URLs you want to choose a new global setting for…click on ‘Add URL’.
Step 3: Select ad settings for new URL groups Since you don’t want ads displaying on those pages, toggle off all ads format for those pages and click on ‘next‘.
Source: https://www.naijahomebased/stop-google-ads-from-displaying/
I can recommend the free plugin Advanced Ads for this mission. You can easily select the pages on which you want to (not) inject this code. Installation and setup will take around 10 minutes, but afterward, you can add pages without any need to touch code.
Here is a tutorial about this setup with Advanced Ads: https://wpadvancedads/how-to-block-ads-on-a-specific-page/
本文标签: Block Adsense on specific page
版权声明:本文标题:Block Adsense on specific page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745620469a2666651.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$dont_display = array(1,15,2106);
, only display your code, if current id is not one of thoseif ( ! in_array($post_id, $dont_display)) { /* your html code here */}
– kero Commented Jul 13, 2017 at 9:21