XF 2.2 Removing advertising from specific pages

Is there a way to not show Google Adsense advertisements on some specific Xenforo pages?
Some pages with more sensitive information Google asks to remove the advertising, under penalty.
I tried to do this using Xenforo's template syntax conditional statements but I couldn't.
Example:

Code:
<xf:if is="!in_array($xf.fullUri,[
    'adrenaline.com.br/forum/threads/sleeping-dogs-topico-oficial.412275/page-26',
    'https://adrenaline.com.br/forum/login/'
])">
<!-- Adsense -->
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</xf:if>

But when I look at source code using browser code inspector (F12) it shows this link anywhay.
 

Brogan

XenForo moderator
Staff member
Conditional statements will do that.
The exact statement required will depend on which pages you wish to hide ads from.

For example, to prevent ads in a specific template you would use: <xf:if is="!$__globals.template == 'forum_list'">

To prevent ads in a specific thread: <xf:if is="!$__globals.thread.thread_id">
That may require passing the thread ID to the PAGE_CONTAINER template, depending on which template you are using to display ads.
 
Conditional statements will do that.
The exact statement required will depend on which pages you wish to hide ads from.

For example, to prevent ads in a specific template you would use: <xf:if is="!$__globals.template == 'forum_list'">

To prevent ads in a specific thread: <xf:if is="!$__globals.thread.thread_id">
That may require passing the thread ID to the PAGE_CONTAINER template, depending on which template you are using to display ads.
Just to see if I got it right:
In this example I gave then I should have it to work:

Code:
<xf:if is="!$__globals.thread.412275">
<!-- Adsense -->
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</xf:if>
?

And for multiple threads that Google claims, it should be:

Code:
<xf:if is="!$__globals.thread.412275 AND !$__globals.thread.999 AND !$__globals.thread.111">
<!-- Adsense -->
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</xf:if>

and so on?

Or maybe would be better use xf:if, xf:else, xf:elseif rather than AND conditions? Only concerned with performance.

Finally, no tools or addons to do this, right? Only with conditionals.

Thanks have a good week.
 

Brogan

XenForo moderator
Staff member
For multiple conditions, use an array: <xf:if is="!in_array($var, ['thing', 'other_thing'])">

For example: !in_array($xf.reply.contentKey, ['thread-24','thread-60'])

Again, the exact statement syntax depends on where the ad content is placed and which vars are available to that template.

This guide will help with identifying the vars.

 
Top