How to insert Ads between Posts in WordPress

While inserting ads in the post content automatically is easy, adding them between posts on your homepage, category pages, or other archives of your WordPress site is a bit more complicated. Advanced Ads has a couple of options for doing that manually or automatically.

This tutorial shows the most straightforward solutions our ad plugin for WordPress can currently provide to insert an ad in a loop.

When to place ads on post lists

Many users asked me when and how to place ads on their home page or other lists of posts. These ads can work well if these pages get a lot of traffic.

I find placing one ad after the first or second post on archive pages worth it. You could repeat it two or three posts later.

In general, I would place only a few ads in the feeds. The chance of getting a click on a banner does not significantly increase if you insert them too low. In addition, each new ad could increase the load times unless you enable lazy loading ads in Advanced Ads Pro.

Try to use ad types that look similar to the posts in the post list. E.g., AdSense In-feed ads are dedicated to this position and try to mimic the layout of your site automatically.

4 different methods to embed ads into post lists

You can use the following four methods to insert ads into your post lists and archive pages.

Inserting ads between posts automatically with the Post Lists placement

The Post Lists placement allows you to place an ad between posts on your home page or any other archive. You can set up the placement directly from the WordPress backend.

The Post Lists placement comes with Advanced Ads Pro. You can find it under Advanced Ads > Placements. A simple placement setting might look like this:

Settings for the post list placement in  Advanced Ads
Settings for the Post List placement in Advanced Ads

As you see, you can select the ad or group and position from the placement settings. Create multiple automatic injections if you want to show more than one ad in the post list.

Get Advanced Ads Pro and start using the Post Lists placement.

In most cases, the ad is now added correctly just by using the Post List placement. The following examples show that it is also possible to inject ads between posts in more complex themes and with some layout adjustments.

Case study: Pocono Theme

In most cases, the ad is now added correctly just by using the Post Lists placement. The following examples show that injecting ads between posts in more complex themes and with some layout adjustments is also possible.

Example homepage for ad injection
We are going to inject an ad between the posts on this home page.

The theme uses a static page as its home page with a post list on it. While this is not a typical WordPress archive page, the Post List placement can still inject ads into it. In addition, the user wanted to inject the ad only between posts on the home page and not on other archive pages.

In the first step, our user created the Post Lists placement with the settings below.

Post List Placement settings for the Pocono theme
Post List settings for the Pocono theme

These settings ensure that the AdSense ad mentioned appears between the first and second posts. The enabled “Secondary loops” option inserts the advertisement in a loop even though the home page is a static page. The “Specific Pages” condition limits the ads between posts to the home page and not other archives.

While the above setup places the ad technically between the posts, there is a gab missing right of the ad.

AdSense ad in a post list
The injected ad between posts still needs some layout work to be done.

Most themes and plugins that build a post grid use a wrapper around each element. This ensures that the same layout applies to all items in the list. In the case of Pocono, the elements are wrapped in a container with the post-column class. We had to add the class to the ad’s settings and set the “Position” option to center the ad.

Specify the CSS class for an ad unit
Add the container class to the ad units that you want to insert in the loop

A frontend developer can find this class by looking into the site’s source code. In this case, our email support helped the client set it up correctly.

When you visit the user’s website’s home page, you will see a perfectly aligned AdSense ad between the posts.

Perfect aligned AdSense unit between posts in WordPress
After specifying the CSS class, the ad unit in the loop is perfectly aligned

The whole setup also works on mobile devices since we set up our ad in a container that behaves like other posts in the lists.

If your post list is not based on the default loop or has a specific design, consider the Custom Position option below.

Use the Custom Positions placement for advanced layouts

Some themes derive from using WordPress standards to build post lists. In these rare cases, even the flexible options of the Post List placement can’t place the ad between posts. The Custom Position placement coming with Advanced Ads Pro is the solution here since it practically allows you to place ads anywhere.

Using the Pocono theme, the Custom Position placement can accomplish the same setup as the Post List placement above.

The user can select the position of the ad in the front end instead of in the WordPress admin dashboard.

The custom position picker is a helpful tool to integrate ads into archive pages
Selecting the position of an ad in the frontend of your site.

To do that, click the “Select position” button in the placement settings. You will now see the website’s front end, where you can click on an element to select it.

We can practically select any element on the site and append an ad to it. Once selected, the page leads back to the placement settings, where we can review and save the selected element.

Settings of the Custom Position placement with the ads targeting the position between posts on the home page.
The options of the Custom Position placement allow us to select a position in the frontend.

If needed, you can adjust the output between the posts with custom CSS rules. You can add them using the Custom Code option on the ad edit screen. Ask your frontend or the theme developers for help, or reach out through email support.

Get Advanced Ads Pro and start using the Custom Position placement.

Implement ad units with the AdSense In-feed placement

The free plugin In-feed ads for Google AdSense in conjunction with Advanced Ads, provides another method to inject Google AdSense In-feed ads into your post lists automatically. It is critical to note that this method solely supports Google AdSense In-feed ads.

To utilize this method, locate and install the plugin In-feed ads for Google AdSense in your WordPress dashboard. Once installed, create a new placement within the Advanced Ads placements settings and select “AdSense In-feed” as your placement type.

Upon creating the placement, choose an AdSense In-feed ad to assign to this placement. In the placement settings, specify where the chosen ad should be inserted within your post lists.

AdSense Infeed placement options
Choose in the placement options where to inject the ad unit

After these steps, save the changes and check if the ad unit appears on your front end.

This method only supports Google AdSense In-feed ads, so consider alternative methods for other ad types. For more in-depth guidance on creating and implementing the AdSense In-feed placement, refer to this dedicated manual.

Insert ads between posts manually in your template

If you are a WordPress developer, you can use PHP to insert an ad in a loop.

Depending on the archive page type, you might find different template files in your theme. Quite often, they use the same template to load the loop. In that case, you’d only adjust one of the template files to place an ad between posts on any of these pages.

I would suggest starting with the archive.php file to see if it contains the loop or if it loads a different template for this.

If you want to show any content only between specific posts (e.g., the fourth and the fifth), you can use the code from below.

// global $wp_query; // uncomment if loop content is in another file or function
if( $wp_query->current_post === 4 ){ 
   // your content goes here
}

When managing your ads with Advanced Ads, you can use an ad placement in the code below. A placement allows you to change the ad delivered between posts through the WordPress backend without changing the code.

// global $wp_query; // uncomment if loop content is in another file or function
if( function_exists('the_ad_placement') && $wp_query->current_post === 4 ){ 
    the_ad_placement('between-posts');
}

The code above shows how this could look like with a Manual Placement that has the ID between-posts. Follow these steps to create the placement and get the appropriate ID:

  1. Navigate to Advanced Ads > Placements
  2. Create a new placement using the “Manual Placement” type
  3. Click on the “Usage” link in the placement table
  4. Copy the ID given in the shortcode or PHP function

The code above gives developers the most control over the ad injection. Still, it would be best if you kept a few things in mind:

  • Backup the theme files before making any changes
  • Keep FTP access at hand to revert any changes in case they break your site
  • Create a child theme of your theme if you want to keep using auto-updates

If coding is not your strength, get Advanced Ads Pro and use the Post List placement.

Author image Thomas

Starting in 2009, Thomas’ own word game website grew to 40 MM page impressions per month. He then built Advanced Ads to help his colleagues to place ads and test different ad positions and networks tests without any coding skills. Thomas now enjoys improving the product for our more than 150,000 users worldwide.

With over a decade of industry expertise, Advanced Ads is your surefooted ally in the ad tech realm. Their array of WordPress ad manager plugins enhances your advertising strategy, ensuring effective ad placements. Rely on their ad tech proficiency to stay ahead in the dynamic world of digital advertising. Contact info

Advanced Ads icon

Make it better

Increase your ad management skills without spending more time.
Join over 150,000 publishers and AdOpts increasing their ad revenue.