WordPress.org

Plugin Directory

Ad Inserter

Insert any HTML/Javascript/PHP code into WordPress. Perfect for AdSense or contextual Amazon ads. 16 code blocks, many display options.

I have activated Ad Inserter. How can I use it?

  1. After activation, click "Settings / Ad Inserter" to access the setup page.
  2. Put ad (or any other HTML/Javascript/PHP) code into the ad box.
  3. Set display options.
  4. Save settings.

How can I replace deprecated widgets with the new one?

  1. This is needed ONLY if you have used widgets with Ad Inserter version 1.4.1 or older
  2. Locate all code blocks that are configured as widgets.
  3. Locate all widget positions (sidebars) where you have the old Ad Inserter widgets (warning message should list them).
  4. Drag new "Ad Inserter" widget to the position where there is the old, deprecated widget.
  5. Select code block for this widget to be the same as it is for the old one.
  6. Drag the old, deprecated widget to the left to remove it.
  7. Replace steps for all old widgets.

How can I replace deprecated tags {adinserter n} for manual insertion with new ones [adinserter block="n"] in all posts?

Use Search Regex plugin to replace tags in all posts with few clicks. If you are not familiar with regular expressions simply use search and replace text for each code block. Use Replace to test replacements and when it works as expected use Replace & Save.

How can I disable ads on specific posts/pages?

  1. Go to Ad Inserter settings page and define default display options for post/page.
  2. Enable automatic display on posts/pages and choose default display: On all, On all except selected or Only on selected.
  3. Go to post/page editor and open Ad Inserter Exceptions meta box below.
  4. Check default display options for wanted code blocks.
  5. Set exceptions for this post or page.

I'm using responsive theme. How can I show or hide some ads on mobile devices?

Select device types (desktop, tablet or phone) for which you need to show ads and enable only client-side device detection.

Which device type detection should I use?

In most cases you should use ONLY client-side detection. All code blocks are generated, however, they are displayed according to settings and browser's screen width using CSS Media Queries. This works perfectly in responsive designs.

How can I disable ads for direct visitors?

Blacklist # as referer.

How can I disable ads on 404 page?

Use the following PHP code (check Process PHP):

<?php
if (!is_404()) {
?>

AD CODE

<?php
}
?>

How can I enable or disable ads on group of similar pages?

If those pages have something in common in the url (page address) then you can block them with url patterns. Use * to define url pattern to whitelist (enable) or blacklist (disable).

  1. To filter all urls starting with /url-start use /url-start*
  2. To filter all urls that contain url-pattern use *url-pattern*
  3. To filter all urls ending with url-end use *url-end

For example, to exclude ads on pages that have /shop/ in url (page address) blacklist the following url: */shop/*

How can I put an ad in the middle of the post regardless of the number of paragraphs?

Put 0.5 as paragraph number. Value between 0 and 1 means relative position in post or page (e.g. 0.3 means paragraph 30% from top or bottom)

I'd like to rotate my ad codes based on percentage, for example show one ad 75% of the time and another one 25% of the time. Is that possible?

Yes, simply create block with 4 ads separated with |rotate|: 3 times ad1 and 1 time ad2.

How can I show different ads to different visitors according to a url query parameter?

For example, use the following code for block 1 and enable PHP processing for this block:

<?php
if (isset ($_GET ['src'])) {
  switch ($_GET ['src']) {
    case 'email':
        echo adinserter (2);
        break;
    case 'facebook':
        echo adinserter (3);
        break;
    case 'twitter':
        echo adinserter (4);
        break;
    default:
        echo adinserter (5);
  }
} else echo adinserter (6); // no src parameter
?>

How can I use PHP code for code block?

Enter PHP code surrounded by PHP tags and check Process PHP. Example:

<div style="width: 100%;">
Some HTML/Javascript code
</div>
<?php echo "PHP code by Ad Inserter"; ?>

How can I insert post category name into my ad code?

  1. Use {category} in the ad. This will be replaced with the post category name.
  2. You can also use
  • {title} - Title of the post
  • {short_title} - Short title (first 3 words) of the post title
  • {category} - Category of the post (or short title if there is no category)
  • {short_category} - First words before "," or "and" of the category of the post (or short title if there is no category)
  • {tag} - The first tag or general tag if the post has no tags
  • {smart_tag} - Smart selection of post tag in the following order:
    • If there is no tag then the category is used;
    • If there is a two-word tag then it is used;
    • If the first tag is a substring of the second (or vice versa) then the first tag is not taken into account
    • If the first and second tags are single words then both words are used
    • First three words of the first tag
    • General tag
  • {search_query} - Search engine query that brought visitor to your website (supports Google, Yahoo, Bing and Ask search engines), {smart_tag} is used when there is no search query. You need to disable caching to use this tag. Please note that most search queries are now encrypted.

How can I rotate few versions of the same ad?

Enter them into the ad box and separate them with |rotate| (vertical bars around text rotate). Ad Inserter will display them randomly. Example:

ad_code_1
|rotate|
ad_code_2
|rotate|
ad_code_3

How can place ads below Read More tag?

Configure ad block with the following options:

  • Automatic display: After Paragraph
  • Paragraph Number: 1
  • Count only paragraphs that CONTAIN: <span id="more-

How can I insert code block directly into template php file?

Enable PHP function adinserter for code block and call adinserter function with code block number as parameter. Example for block 3:

<?php if (function_exists ('adinserter')) echo adinserter (3); ?>

This would generate code as defined for the code block number 3.

How can I create contextual Amazon ad (to show items related to the post)?

Sign in to Amazon Associates, go to Widgets/Widget Source, choose ad type and set parameters. For titles and search terms use tags. For example, the code below would display 5 amazon items related to the post tag - check above for all possible tags.

<div style="height: 531px;">
<script type="text/javascript">
var amzn_wdgt={widget:"Search"};
amzn_wdgt.tag="ad-inserter-20";
amzn_wdgt.columns="1";
amzn_wdgt.rows="5";
amzn_wdgt.defaultSearchTerm="{smart_tag}";
amzn_wdgt.searchIndex="All";
amzn_wdgt.width="300";
amzn_wdgt.showImage="True";
amzn_wdgt.showPrice="True";
amzn_wdgt.showRating="True";
amzn_wdgt.design="2";
amzn_wdgt.colorTheme="Default";
amzn_wdgt.headerTextColor="#0000AA";
amzn_wdgt.outerBackgroundColor="#FFFFFF";
amzn_wdgt.borderColor="#FFFFFF";
amzn_wdgt.marketPlace="US";
</script>
<script type="text/javascript" src="http://wms.assoc-amazon.com/20070822/US/js/AmazonWidgets.js">
</script>
</div>

Another example for nice contextual carousel below posts:

<div style="overflow: auto; width: 100%;">
<script type='text/javascript'>
var amzn_wdgt={widget:'Carousel'};
amzn_wdgt.tag='ad-inserter-20';
amzn_wdgt.widgetType='SearchAndAdd';
amzn_wdgt.searchIndex='All';
amzn_wdgt.keywords='{smart_tag}';
amzn_wdgt.title='{title}';
amzn_wdgt.width='460';
amzn_wdgt.height='250';
amzn_wdgt.marketPlace='US';
</script>
<script type='text/javascript' src='http://wms.assoc-amazon.com/20070822/US/js/swfobject_1_5.js'>
</script>
</div>

Center alignment does not work for some ads!

Some iframe ads can not be centered using standard approach so some additional code is needed to put them in the middle. Simply wrap ad code in a div with some style e.g. left padding. Example:

<div style="padding-left: 200px;">
ad_code
</div>

How can I rotate between different alignments so I can test an ad aligned to the right against an ad aligned to the left?

Set Block Alignment and Style to "No Wrapping" and create manual wrapping around both ads separated with |rotate|:

<div style="float: left; margin: 0 8px 8px 0;">
AD CODE LEFT
</div>

|rotate|

<div style="float: right; margin: 0 0 8px 8px;">
AD CODE RIGHT
</div>

Requires: 3.0 or higher
Compatible up to: 4.5.3
Last Updated: 2 months ago
Active Installs: 30,000+

Ratings

4.9 out of 5 stars

Support

31 of 34 support threads in the last two months have been marked resolved.

Got something to say? Need help?

Compatibility

+
=
Not enough data

2 people say it works.
0 people say it's broken.

100,1,1 100,2,2
100,1,1 100,3,3
100,2,2
67,3,2
100,4,4
100,1,1 100,1,1 100,1,1
100,1,1
100,2,2 100,1,1
100,1,1
100,1,1
100,2,2
100,7,7
100,2,2
100,4,4
100,1,1
100,1,1
100,1,1
100,1,1 100,2,2 100,1,1 100,2,2 100,1,1
100,1,1 100,1,1
100,1,1 100,1,1 100,1,1
100,2,2
100,1,1
100,1,1
100,1,1
100,1,1
100,1,1 100,1,1 100,2,2 100,1,1
100,1,1 100,1,1 100,1,1 100,2,2
100,1,1 100,1,1
100,1,1
100,1,1 100,1,1 100,2,2
100,1,1
100,1,1
100,2,2
100,2,2 100,1,1 100,2,2
100,1,1 100,1,1
100,1,1 100,3,3 100,1,1 100,1,1 100,1,1
50,2,1
100,2,2
100,2,2 100,1,1
100,2,2