1. 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?

Discussion in 'XenForo Questions and Support' started by CyclingTribe, Aug 2, 2013.

  1. CyclingTribe

    CyclingTribe Well-Known Member

    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?

    Shaun :D
  2. Brogan

    Brogan XenForo Moderator Staff Member

    I use this:

    <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.
    popowich and nrep like this.
  3. CyclingTribe

    CyclingTribe Well-Known Member

    Excellent - thanks Paul - I'll have a play with it. (y)
  4. Martok

    Martok Well-Known Member

    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?
  5. MattW

    MattW Well-Known Member

    @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?
  6. Martok

    Martok Well-Known Member

    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.
  7. MattW

    MattW Well-Known Member

    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 ?


  8. MattW

    MattW Well-Known Member

    Sorted it. I use footbot honey pot, which uses it's own register page: Foolbothoneypot_register_form
    CyclingTribe likes this.
  9. Brogan

    Brogan XenForo Moderator Staff Member

    The error pages don't use a template so there's no easy way of targeting them.
  10. Aurèle

    Aurèle Member

    Hello @Brogan, did you find a way to stop ads on error pages ? Did something change regarding the templating ?

    Thanks for sharing this snippet :

    I'll use it for my own forum.
  11. Brogan

    Brogan XenForo Moderator Staff Member

    Aurèle likes this.
  12. melbo

    melbo Well-Known Member

    'login_two_step' would suppress on 2FA screen?
  13. Sportsoutlaw

    Sportsoutlaw Member

    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!
    Aurèle likes this.
  14. GamerSize

    GamerSize New Member

    I know this post is super old but cant you just do this

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

    <div class="banner-728-90">
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!-- bredcrumb -->
    <ins class="adsbygoogle"
    (adsbygoogle = window.adsbygoogle || []).push({});
  15. GamerSize

    GamerSize New Member

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

    that should work if you use what i posted above
  16. Brogan

    Brogan XenForo Moderator Staff Member

    That is against Google's ToS.
    GamerSize likes this.
  17. Chris D

    Chris D XenForo Developer Staff Member

    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:


    (Though bear in mind some of those templates probably have different names now ;))
    JordanH, Skylined, GamerSize and 3 others like this.
  18. CyclingTribe

    CyclingTribe Well-Known Member

    That's a neat idea @Chris D - nice one - should make it a lot easier. (y)
  19. GamerSize

    GamerSize New Member

    Cant wait for the release. Its going to have that brand new car feel :cool:

Share This Page