Strategy for ads placement with Infinite Scroll (WordPress)

By | January 22, 2013

Some high profile website (Facebook, Linkedin) have enable infinite scroll (automatically displays following pages when the user scroll down) on their pages.
This is mostly because infinite scroll is supposed to increase user stickiness to a site. One obvious problem with infinite scroll is that the ad placement needs to be updated.

Without infinite scroll the user would likely browse from page to page and the ads where evenly distributed across the page and most likely on top of the page, where most users spent most time.

Now that the content is automatically loaded, the users’ time is spent at the bottom of your pages. Not exactly what most site are optimized for.

A simple work-around is to have your Ads placed on a container (div) that sticks to a fixed position inside your page, independently of any scroll.

Doing so is quite easy, let me share the solution I used on my WordPress blog.

The files that needs to be modified can be found in the theme folder used for your blog (…\wp-content\themes\yourtheme).


Needs to be modified to add style for 3 divs.
Fixed position will force the div to stay at a position, independently of the scroll made on the page.
Margin are used to correctly place the ad, change below value according to the setting of your theme.
Width and Height are the size of the ads you want to display.

/* Google Ads Placement */
    width: 25px;
    height: 25px;

/* Google Ads Placement in Content*/
    width: 25px;
    height: 25px;

/* Google Ads Placement large*/
#LargeGoogleAds {
    opacity: 1 !important;


Insert code below the header closure element: </header><!– #branding –>

<?php$pos = strpos($_SERVER[‘HTTP_USER_AGENT’], “Mobi”);
if ($pos === false)
// Not a mobile Ads, show sidebar Ads.?> <div

/* Copy your ad code here */


I also wanted to take care of the mobile devices, below ad is going to be displayed only on a mobile device.
Insert code after the “main” div: <divid=main>

if ($pos !== false) {
// Show mobile Ad only!
/* Copy your ad code here */

<?php }

0 Kudos

5 thoughts on “Strategy for ads placement with Infinite Scroll (WordPress)

    1. Ahmet Post author

      No, this was done by directly editing the php and css files. However, please see the disclaimer below.

  1. jonnybliss

    Hi! I am developing a wordpress site right now and I’m having a hard time with implementing both an infinite scroll and a fixed ad position. The fixed ad position is within each article. So it goes from point a to point b within an article, then the next article has another ad that goes from point a to point b. I can do a fixed ad that runs along the side the infinite scroll content but I’m having trouble with implementing within each article. Any advice?

    1. Ahmet Post author

      Hi Jonny,
      for within each article you should take the same approach as the one you use for the articles themselves. What issue are you facing?