• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.2 Stop Adsense ads appearing on XF error pages?

CTXMedia

Formerly CyclingTribe
#1
I'm currently only displaying ads to guests so have a conditional wrapped around the Adsense code:

<xen:if is="!{$visitor.user_id}">

How would I expand on this to ensure ads are not displayed on error pages that XF generates?

Thanks,
Shaun :D
 

Brogan

XenForo moderator
Staff member
#2
I use this:

Code:
<xen:if is="!in_array({$contentTemplate}, array('error', 'search_form', 'search_form_post', 'search_form_profile_post', 'xengallery_search_form_media', 'search_results', 'register_form', 'login', 'error_with_login', 'thread_view', 'cta_overtaking_index'))">
Obviously there are some templates specific to my site and configuration there.
 

CTXMedia

Formerly CyclingTribe
#3
I use this:

Code:
<xen:if is="!in_array({$contentTemplate}, array('error', 'search_form', 'search_form_post', 'search_form_profile_post', 'xengallery_search_form_media', 'search_results', 'register_form', 'login', 'error_with_login', 'thread_view', 'cta_overtaking_index'))">
Obviously there are some templates specific to my site and configuration there.
Excellent - thanks Paul - I'll have a play with it. (y)
 

Martok

Well-known member
#4
This works a treat on everything except for 404 pages. I thought I might be doing something wrong but have even checked @Brogan's site and it's the same problem there - if the page doesn't exist the error page displays adverts.

Any idea why 'error' in the array isn't working in this case?
 

MattW

Well-known member
#5
@Brogan - What are you using to stop adsense on the login page? I've tried the login template in the array, but it's still showing on my site?
 

Martok

Well-known member
#6
@Brogan - What are you using to stop adsense on the login page? I've tried the login template in the array, but it's still showing on my site?
It's fine on my site and I've just used Brogan's code. It looks like you've included the code in the ad_above_top_breadcrumb template as the advert doesn't show on the login page but you've not added it to ad_below_bottom_breadcrumb as that is the advert that still shows.


It's just the 404 pages that are still showing adverts.
 

MattW

Well-known member
#7
It's fine on my site and I've just used Brogan's code. It looks like you've included the code in the ad_above_top_breadcrumb template as the advert doesn't show on the login page but you've not added it to ad_below_bottom_breadcrumb as that is the advert that still shows.


It's just the 404 pages that are still showing adverts.
I have them on above top breadcrumb, and below bottom breadcrumb. I'm testing the conditional on the top breadcrumb before applying it to the bottom one as well.

It's not displaying when the URL ends in login, but for some reason, after the second attempt, it's showing login/login ?

http://www.z22se.co.uk/login/login

login.PNG
 
#10
The error pages don't use a template so there's no easy way of targeting them.
Hello @Brogan, did you find a way to stop ads on error pages ? Did something change regarding the templating ?

Thanks for sharing this snippet :

Code:
<xen:if is="!in_array({$contentTemplate}, array('error', 'search_form', 'search_form_post', 'search_form_profile_post', 'xengallery_search_form_media', 'search_results', 'register_form', 'login', 'error_with_login', 'thread_view', 'cta_overtaking_index'))">
I'll use it for my own forum.
 
#13
Just a word of warning to anybody using adsense, be sure to use this conditional around your ad code. I have had adsense on sites for well over 10 years, and never thought about it, nor had it been an issue.

Yesterday, I received a warning from adsense due to content displaying on an "non content" page. It was an error page for a thread that had been removed.

Thanks @Brogan for putting this together, saved me a ton of headache tonight!
 
#14
I know this post is super old but cant you just do this


Code:
---extra.css---

.error .banner-728-90 {
   display: none;
 
}



Code:
<div class="banner-728-90">

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- bredcrumb -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-00000000000"
     data-ad-slot="0000000000"
     data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
 

</div>
 
#15
I have them on above top breadcrumb, and below bottom breadcrumb. I'm testing the conditional on the top breadcrumb before applying it to the bottom one as well.

It's not displaying when the URL ends in login, but for some reason, after the second attempt, it's showing login/login ?

http://www.z22se.co.uk/login/login

View attachment 56759

Code:
.login .banner-728-90 {
   display: none;

}

that should work if you use what i posted above
 

Chris D

XenForo developer
Staff member
#17
Seeing this thread popping up inspired us to consider how we can improve this in XF2.

As we have a better system for the management of advertising in XF2, we've added an option which allows you to list templates which globally shouldn't display any advertising.

By default this happens on all error pages (error template) and message only templates (message_page template), though of course you can add your own.

So taking @Brogan's old example literally, you would now just do this in the Appearance option group or, conveniently, below the advertising list in the Admin CP:

upload_2017-7-6_16-4-5.png

(Though bear in mind some of those templates probably have different names now ;))