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.
Table of Contents
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:
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.
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.
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.
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.
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.
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.
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.
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.
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:
- Navigate to Advanced Ads > Placements
- Create a new placement using the “Manual Placement” type
- Click on the “Usage” link in the placement table
- 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.