jQuery .ajax doesn't load Google Adsense

Posted by Sahas Katta on Stack Overflow See other posts from Stack Overflow or by Sahas Katta
Published on 2010-12-25T21:49:31Z Indexed on 2010/12/25 21:54 UTC
Read the original article Hit count: 151

Filed under:
|
|

Hey Everyone, Just ran into an odd issue. I have a simple WP loop and instead of regular NEXT/BACK pages, I use a jQuery powered $.ajax get to append the following page to the current page. It works perfectly. However, I choose to insert a Google Adsense unit every 5th story. Unfortunately, the Adsense unit that is brought in with a second, third, or etc page load don't render.

Here's my loop: 10 stories per page, Adsense after the 4th one.

<?php $count = 0; ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php $count++; ?>

<div class="card">
  <div class="title">
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><span><?php the_title(); ?></span></a>
  </div>
</div>

<?php if ($count == 4) : ?>
<div class="card">
<!-- ADSENSE CODE HERE (Straight from Google Adsense Panel, no tweaks.) -->
</div>
<?php endif; ?>

As for my jQuery script, here's how that looks:

$.ajax({
  url: nextPageLink,
  type: 'GET',
  success: function(data) {
  $(data).find('#reviews .card').appendTo('#reviews');
  },
  error: function(xhr, status, error) {
  $('.loadination').addClass('hidden');
  }
});

Keep in mind, I just simplified my code to give you guys an example. The code above was just the essentials. All the loading stuff works perfectly. Images, text, links, etc all load just fine. However, the Google Adsense unit doesn't.

Any help would be appreciated. Thanks and Happy Holidays!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about Wordpress