• Welcome to XF2 Addons. You can buy my Premium membership for $35 per year, and this gives you access to download any or ALL of the 335 add-ons that I have developed for Xenforo 2.x. In addition, Premium members will get technical support. Once the Premium membership has expired you can continue to use the installed addons on your forum as long as you like.

Advertising - AdSense setup


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 300x50
  5. Click Responsive and select Fixed
  6. Enter 300 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 300x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:300px;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 300x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:300px;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 300x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:300px;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 300x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:300px;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 300x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:300px;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 300x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:300px;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;
	}
}
 

Andy

Administrator
Staff member
Please note I have edited the above posts to show the new Fixed ad size of 300x50. It's important that anyone using the above code to update to fixed 300x50 so that on mobile phones the ads are smaller.

Start by going to your AdSense control panel and update the 320x50 to 300x50. Be sure to rename the ad unit also. Then update your XenForo Advertising page with the new 300x50 values.
 
Similar threads

Similar threads

Top