WordPress Tutorials

Adding AdSense Ads between WordPress posts

This guide explains how to place Google AdSense ads between posts on a WordPress blog index or archive page. The original method was written for older classic WordPress themes, so the template names and markup may not match modern themes such as Astra.

For current WordPress sites, make changes in a child theme or use a maintained ad-management solution rather than editing the parent theme. Back up the site first and test the placement on desktop and mobile. Keep ads clearly distinguishable from post content and navigation, and follow Google's current AdSense ad placement policies.

If you want to place ads on category archive pages instead, see How to Add AdSense Ads Between Posts on WordPress Category Pages.

Website analytics dashboard on a computer monitor for online advertising

How to Insert AdSense Ads Between WordPress Posts

The exact insertion point depends on your active theme. In a classic theme, the ad markup must be placed inside the main post loop, after the post markup you want it to follow. Do not assume that a file named index.php or a class such as entry exists in your current theme. Astra uses its own template structure, and a parent-theme edit can be overwritten during an update.

1. Back up your site and use a child theme

Make a backup before editing PHP. Use a child theme or a suitable code-management workflow, and avoid editing the parent theme directly. If you are not comfortable tracing the active theme's post loop, use an ad plugin that explicitly supports archive placements.

2. Find the post loop

In the template that renders the blog index or archive, locate the loop that outputs each post. The ad should be inserted after the selected post's complete markup but before the loop advances to the next post. Placing it inside the opening post container can make the ad look like part of the article and may cause layout or policy problems.

3. Insert the ad at the desired position

For a classic PHP template where $wp_query is the active main query, this conditional illustrates how to target the first post after its markup. Put it inside the loop, after the post's closing markup and before the loop ends. Replace the placeholder with the ad unit code supplied by AdSense; do not paste the placeholder literally.

<?php if ( isset( $wp_query->current_post ) && 0 === $wp_query->current_post ) : ?>
  <div class="archive-ad-placement">
    <!-- Insert your AdSense ad unit code here -->
  </div>
<?php endif; ?>

This is an insertion-point example, not a drop-in Astra snippet. The correct location and query object depend on the template. If you want the ad after the second post instead, change 0 to 1; the loop's post index starts at zero.

4. Test the placement

Preview the archive while logged out and check desktop and mobile layouts. Confirm the ad is outside the post's article container, does not resemble a post title or navigation link, and does not cause accidental clicks or excessive layout shifts. Ad serving may not appear immediately, and you should never click your own ads while testing.