The Post Content placement allows you to automatically inject ads into the content of your posts and pages based on paragraphs, headlines, images or any other element on your website.
Since ads within the content are the best performing ones, this placement can have a large impact on the ad revenue, if used correctly.
Table of Contents
Injecting an ad into the content
In order to inject an existing ad or ad group into the content of your posts, you need to create at least one Post Content placement. Go to Advanced Ads > Placements and create a new placement with the type represented by the following icon:
The placement you will now see in the list should look similar to the one on the next image:
In this example, the placement injects our Medium Rectangle ad after the 2nd paragraph on each post.
Ad Injection elements
You can inject ads based on practically any element in the content.
- images (includes galleries)
- list items (
- containers (
- any element with visible text in it
You can also use the “custom” option to build your own injection rules.
Custom injection rules
The “custom” injection rule comes with a tool to help you pick the position of your ad in the frontend just by clicking on it with your mouse. Just click the select position button to start that tool.
A click on “select position” brings you to the last published post on your site. You can navigate to other pages by entering another URL directly or clicking on any link.
The frontend picker allows you to select any element that is technically in the content of your site (tech talk: everything wrapped in the
the_content filter). This can be more than just the main blog text if you are using a page builder. The mouse cursor looks different when a position can or can’t be selected.
Here are a few examples on injecting ads using the “custom” option.
brto inject ads based on
<br/>tags or any other specific HTML element
p/following-sibling::p+ set the “before” position to only inject ads between paragraphs and not before any other tags, e.g., images
CLASSwith the exact classes of a any element in the content to inject ads next to it
Please note that while ads for most pre-defined options like “paragraph” or “headlines” are only injected if these elements include visible text, the “custom” option also counts elements without any text in them.
You can built more sophisticated rules based on XPath. Please find examples in the XPath cheatsheet.
These are options added by Advanced Ads Pro to especially extend the functionalities of the Post Content placement.
Repeat the position
Repeat the ad. E.g., if you set it to display after the second paragraph, checking this option would result in the ad to show up automatically after the fourth, sixth, eighth, etc. paragraph as well.
Note: not every ad network might support this. So far, we learned that media.net doesn’t. AdSense works.
Minimum Content Length
Set a minimum length of the content before an ad is injected into it.
Words between ads
This option lets you define a minimum amount of words in a text section that is necessary before an ad will be injected. The option “Words between ads” will not inject an ad when the number of words after the last injected ad is less than the defined value. This includes paragraphs, headlines, and other text elements.
Prevent ad injection into the content
Pro adds a setting to the Ad Options meta box on the post and page edit pages to disable all automatic content injections for that specific page in the frontend.
Change the order of injected elements
By default, Advanced Ads tries to inject ads to the post content as late as possible. However, this might not always be your attention. To change the priority of the injection, use the following option in Advanced Ads > Settings > General.
Tip: Most injections have a priority between 1 and 20, so when trying to find the right value, start with 10 or 20.
Unlimited ad injection
Some plugins and themes trigger ad injections where it shouldn’t happen. Therefore, Advanced Ads ignores injected placements on non-singular pages and outside the loop. However, this can cause problems with some themes. Set this option to -1 in order to enable unlimited ad injection at your own risk, set it to 0 to keep it disabled or choose a positive number to enable the injection only in the first x posts on your archive pages.
You find this setting in Advanced Ads > Settings > General.
Here are some custom solutions for issues with the content injection placements.
Prevent injection into specific elements
You can prevent automatic ad injection into specific elements by adding the
You can add your own elements with the custom code explained here.
Ad injection without the_content()
If your theme can not use the
the_content function, but
get_the_content() or a similar approach, you can apply the ad injection manually using a line like this in your theme:
echo Advanced_Ads::get_instance()->inject_content( get_the_content() );
Ad injection with a different filter
You can use ad injection on content that uses a different filter, too, when Advanced Ads Pro is enabled. Just set the
ADVANCED_ADS_PRO_CUSTOM_CONTENT_FILTER constant in your
wp-config.php like in the example below. Replace
YOUR_FILTER with your filter string.
define( 'ADVANCED_ADS_PRO_CUSTOM_CONTENT_FILTER', 'YOUR_FILTER' );
The content injection can break for various reasons. Mostly, because of a broken ad code or when the paragraphs can not be counted due to a broken tag. Such issues will be captured in the error log or displayed below the ad when you have
WP_DEBUG enabled in your