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?

    Thanks,
    Shaun :D
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

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

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

    login.PNG
     
  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.

Share This Page