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

Avoid Displaying Ads On XF Error Page, Content Template Is Empty

TheBigK

Well-known member
#1
I'm using following conditional to control advertisements -

Code:
<xen:if is="{$contentTemplate} != 'member_view' && {$contentTemplate} != 'register_form'">
I however want to avoid displaying advertisement when XF shows an error page. One of our members avoids displaying profile to guests and when a guest lands on this member's profile page, advertisement and message - This member limits who may view their full profile. appears.

I thought of adding a rule to avoid displaying ad on the error pages of XF. So I checked for the

<div id="content" class="">

The class is empty. What do I enter to avoid display ads on any of XF error pages?
 

Jake Bunce

XenForo moderator
Staff member
#2
Admin CP -> Appearance -> Templates -> error

Add this code to the top:

Code:
<xen:container var="$errorFlag">1</xen:container>
Now you can check {$errorFlag} in the container scope:

Code:
<xen:if is="!{$errorFlag}">

</xen:if>
 

TheBigK

Well-known member
#3
Admin CP -> Appearance -> Templates -> error

Add this code to the top:

Code:
<xen:container var="$errorFlag">1</xen:container>
Now you can check {$errorFlag} in the container scope:

Code:
<xen:if is="!{$errorFlag}">
 
</xen:if>
I used this -

Code:
<xen:if is="{$contentTemplate} != 'member_view' && {$contentTemplate} != 'register_form' && !{$errorFlag}">
and it seems to be working fine :) . Thanks!
 

Bram

Well-known member
#4
My following code works fine but I am probably doing it all wrong. How do I simplify the current code i use for the Ad_Above_Content template :)

<xen:if is="!{$visitor.user_id}">
<xen:if is="{$contentTemplate} != 'search_form_post'">
<xen:if is="{$contentTemplate} != 'search_results'">
<xen:if is="{$contentTemplate} != 'dark_taigachat_full'">
<xen:if is="{$contentTemplate} != 'register_form'">
<xen:if is="{$contentTemplate} != 'login'">
<xen:if is="{$contentTemplate} != 'error_with_login'">
<xen:if is="!{$errorFlag}">
<div style="text-align: center;">

GOOGLE ADSENSE CODE HERE

</div>
</xen:if>
</xen:if>
</xen:if>
</xen:if>
</xen:if>
</xen:if>
</xen:if>
</xen:if>

One tip to all: make sure you NEVER display ads on the search results pages as Google TOS doesnt allow it. @XenForo: can this be "fixed" in the next 1.2 version?
 

James

Well-known member
#5
@Bram instead of using so many if statements on the contenttemplate variable, why not use one conditional checking in_array and put the relevant templates into the parameters.
 

Brogan

XenForo moderator
Staff member
#6
An example of what James suggested (from my own site):

Code:
<xen:if is="!in_array({$contentTemplate}, array('register_form', 'forum_list', 'cta_overtaking_index'))">
 

RoldanLT

Well-known member
#7
Does displaying adsense ads on error page/like private profiles/thread not found/forum not found is also not permitted by google?
 
#8
One tip to all: make sure you NEVER display ads on the search results pages as Google TOS doesnt allow it.
This is a reply to 2 year old post but... that above is incorrect - you can put Adsense on your own search page (ie. when you are not using Google's search results). See here -> AdSense for search policies - AdSense Help

Can I display ads on non-Google search results pages?
If you have non-Google search results pages on your site, you're welcome to place Google ads on them.