Advertising


Andy

Administrator
Staff member
This thread will explain how to setup your AdSense and XenForo Advertising code.

You will create two AdSense codes:

First AdSense code:
  1. Click Ads
  2. Click By ad unit
  3. Click Display ads
  4. Name your ad unit: fixed 728x90
  5. Click Responsive and select Fixed
  6. Enter 728 for the Width and 90 for the Height
  7. Click the Create button
  8. Copy code
  9. Click Done
Second AdSense code:
  1. Click Ads
  2. Click By ad unit
  3. Click Display ads
  4. Name your ad unit: fixed 325x50
  5. Click Responsive and select Fixed
  6. Enter 325 for the Width and 50 for the Height
  7. Click the Create button
  8. Copy code
  9. Click Done
 

Andy

Administrator
Staff member
Now you will select the XenForo Advertising page.

Admin control panel -> Setup -> Advertising

1587384326763.png
 

Andy

Administrator
Staff member
The HTML code for Container breadcrumb (top): Above.

Code:
<xf:if is="$xf.reply.template == 'forum_list'">
    <div class="advertising-wide">
        <div style="margin-top:10px;margin-bottom:15px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
            <!-- fixed 728x90 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:728px;height:90px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
    <div class="advertising-narrow">
        <div style="margin-top:10px;margin-bottom:15px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
            <!-- fixed 320x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:320px;height:50px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
</xf:if>

<xf:if is="$xf.reply.template == 'forum_view'">
    <div class="advertising-wide">
        <div style="margin-top:10px;margin-bottom:15px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
            <!-- fixed 728x90 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:728px;height:90px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
    <div class="advertising-narrow">
        <div style="margin-top:10px;margin-bottom:15px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
            <!-- fixed 320x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:320px;height:50px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
</xf:if>

<xf:if is="$xf.reply.template == 'thread_view'">
    <div class="advertising-wide">
        <div style="margin-top:10px;margin-bottom:15px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
            <!-- fixed 728x90 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:728px;height:90px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
    <div class="advertising-narrow">
        <div style="margin-top:10px;margin-bottom:15px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
            <!-- fixed 320x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:320px;height:50px"
                 data-ad-client="ca-pub-1816232865955920"
                 data-ad-slot="7173879524"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
</xf:if>
 

Andy

Administrator
Staff member
The HTML code for Container breadcrumb (bottom): Above.

Code:
<xf:if is="$xf.reply.template == 'forum_list'">
    <div class="advertising-wide">
        <div style="margin-top:20px;margin-bottom:10px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
            <!-- fixed 728x90 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:728px;height:90px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
    <div class="advertising-narrow">
        <div style="margin-top:20px;margin-bottom:10px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
            <!-- fixed 320x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:320px;height:50px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
</xf:if>

<xf:if is="$xf.reply.template == 'forum_view'">
    <div class="advertising-wide">
        <div style="margin-top:20px;margin-bottom:10px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
            <!-- fixed 728x90 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:728px;height:90px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
    <div class="advertising-narrow">
        <div style="margin-top:20px;margin-bottom:10px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
            <!-- fixed 320x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:320px;height:50px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
</xf:if>

<xf:if is="$xf.reply.template == 'thread_view'">
    <div class="advertising-wide">
        <div style="margin-top:0px;margin-bottom:0px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
            <!-- fixed 728x90 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:728px;height:90px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
    <div class="advertising-narrow">
        <div style="margin-top:0px;margin-bottom:0px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
            <!-- fixed 320x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:320px;height:50px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
</xf:if>
 

Andy

Administrator
Staff member
Display criteria. I prefer to show AdSense to all visitors and members:

1587388335786.jpg
 

Andy

Administrator
Staff member
Add the following code to the extra.less template:

Code:
// advertising

.advertising-wide
{
	display: inline;
	text-align: center;
}

.advertising-narrow
{
	display: none;
}

@media (max-width: @xf-responsiveMedium)
{
	.advertising-wide
	{
		display: none;
	}
	
	.advertising-narrow
	{
		display: inline;
		text-align: center;
	}
}
 
Top