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.

Need to install ads or widgets on WordPress website?

Ad Inserter is a simple yet powerful solution to insert any code into WordPress. Perfect for AdSense or contextual Amazon ads. Simply enter any HTML/Javascript/PHP code and select where and how you want to display it.

Automatic Display Options:

  • Display Before Content (before post or page text)
  • Display Before Selected Paragraph
  • Display After Selected Paragraph
  • Display After Content (after post or page text)
  • Display Before Title (does not work with all themes)
  • Display Before Excerpt (on blog pages)
  • Display After Excerpt (on blog pages)

Paragraph number for Automatic Display Options Before and After Paragraph:

  • 0 means random paragraph position
  • value between 0 and 1 means relative position in post or page (e.g. 0.3 means paragraph 30% from top or bottom)
  • 1 or more means paragraph number

Paragraphs can be counted from top or from bottom. It is also possible to count only paragraphs that contain/do not contain certain text or count only paragraphs that have some minimum number of words. If more than one text is defined (comma separated) and "contain" is selected then the paragraph must contain ALL texts.

You can also define paragraph tags. Normally only <p> tags are used. If you post contains also <div> or header tags you can define comma separated list of tags used to count paragraphs (e.g. p, div, h2, h3). WARNING: Each code block you insert on post adds one <div> block unelss you use No wrapping style. Before Paragraph will insert code before <tag>, After Paragraph will insert code after closing </tag>. After Paragraph will not work if you specify tag names that have no closing tags!

Additional Display Options:

  • As a Widget - Simply drag Ad Inserter widget to any postition, select code block and you're done
  • Manual - Insert shortcode [adinserter block="BLOCK_NUMBER"] or [adinserter name="BLOCK_NAME"] into post or page HTML code to display block with BLOCK_NAME name or BLOCK_NUMBER number at this position
  • PHP function call <?php if (function_exists ('adinserter')) echo adinserter (BLOCK_NUMBER); ?> - Insert code block BLOCK_NUMBER at any position in template file

Additional Options:

  • Use {category}, {short_category}, {title}, {short_title}, {tag}, {smart_tag} or {search_query} tags to insert actual post data into code blocks
  • Use {author} for post author username or {author_name} for post author name to insert post author data into code blocks (works only inside posts)
  • To rotate different ad versions separate them with |rotate|

Display Block to:

  • All users (default)
  • Logged in users
  • Not logged in users

on:

  • All devices (default)
  • Desktop devices
  • Mobile devices (tablets and phones)
  • Tablet devices
  • Phone devices
  • Desktop and tablet devices
  • Desktop and phone devices

device type detection:

  • Server-side
  • Client-side (default)

IMPORTANT: There are two types of device detection (desktop, tablet or phone): server side and client-side.

Server-side detection of mobile/desktop devices works only when Ad Inserter plugin is called. It is called by WordPress when it needs to generate a page. However, when you are using caching, it saves created page for quicker serving. In such cases the user might get (saved) page for wrong device. To solve this issue use themes that generate separate pages for desktop and mobile devices or use Mobile Theme Switcher plugin.

PLEASE NOTE: Use server-side device type detection only when you need to generate code blocks based on device type. In all other cases switch it off.

Client-side detection of mobile/desktop devices works always as it is done in visitor's browser. CSS media queries and browser's screen width are used to show or hide Ad Inserter code blocks:

  • Desktop: 980 pixels or more
  • Tablet: from 768 pixels to 979 pixels
  • Phone: less than 768 pixels

PLEASE NOTE: In most cases you should use ONLY client-side detection type. Works perfectly with responsive designs as they use CSS media queries.

Block Alignment and Style:

  • No Wrapping (leaves ad code as it is, otherwise it is wrapped by a div)
  • Custom CSS (Custom CSS code for wrapping div)
  • None (simple div with thin margin)
  • Align Left
  • Align Right
  • Center
  • Float Left (ad on left with wrapped text on right)
  • Float Right (ad on right with wrapped text on left)

Check screenshots for explanation on alignment.

PLEASE NOTE: If you are using No Wrapping style and need to hide code on some devices using client-side detection (CSS Media Queries) then you need to add appropriate class to your CSS code (ai-desktop, ai-tablet, ai-phone, ai-desktop-tablet, ai-desktop-phone or ai-tablet-phone).

PHP processing: Enabled or Disabled

Do not display ad if the number of paragraphs or the number of words is below limit (used only for position Before or After selected paragraph).

Display ad only for posts published after N days.

Do not display ads to users from certain referers (domains) e.g technorati.com, facebook.com,... (black list) or display ads only for certain referrers (white list). Use # for no referer (direct visit). Leave referrers list empty and set it to Black list to show ads for all referrers.

Do not display ads in certain caregories e.g sport, news, science,... (black list) or display ads only in certain categories (white list). Leave category list empty and set it to Black list to show ads in all categories. WARNING: If category name contains commas use category slug instead. Also make sure you have enabled display on Category pages.

Do not display ads in posts with certain tags (black list) or display ads only in posts with certain tags (white list). Leave tag list empty and set it to Black list to show ads for all tags. Also make sure you have enabled display on Archive pages.

Do not display ads on pages with certain urls (black list) or display ads only pages with certain urls (white list). Leave url list empty and set it to Black list to show ads on all urls. You can also use partial urls with *. To filter all urls starting with /url-start use /url-start*, to filter all urls that contain url-pattern use *url-pattern*, to filter all urls ending with url-end use *url-end. WARNING: Separate urls with SPACES.

For all display positions you can also define WordPress page types where the ads can be displayed:

  • Posts
  • Pages

You can also disable ads on certain posts or pages. For each code block on posts or pages you first define default display settings. Then you can define post/page exceptions on the post/page editor page (check Ad Inserter Exceptions meta box below). Exceptions work only on page/post content (positions Before Content, Before Paragraph, After Paragraph, After Content).

For display positions Before Excerpt, After Excerpt, Before Title and Widget you can select additional pages where the ads can be displayed:

  • Homepage
  • Category pages
  • Search Pages
  • Archive pages

For display positions Before Excerpt and After Excerpt you can also specify comma separated list of excerpt numbers (1 - 9).

Ad Inserter is perfect for displaying AdSense or Amazon ads. It can also be used to display various versions of AdSense ads using channels to test which format or color combination performs best.

Support for Special Code Blocks:

  • Header scripts (tab #, scripts in the <header> section)
  • Footer scripts (tab #, scripts before the </body> tag)

Wrapping divs for code blocks have 'code-block' and 'code-block-N' classes which can be used for custom styles. Class name 'code-block' can be changed in Ad Inserter settings. If you are using client-side device detection (CSS media queries) then the wrapping div for the code block will have also one of the following classes: ai-desktop, ai-tablet, ai-phone, ai-desktop-tablet, ai-desktop-phone or ai-tablet-phone.

To configure syntax highlighting go to Ad Inserter Settings (tab #) and choose theme.

You can also easily copy settings from one block to another. Click on the Import/Export icon next to the Save button. Select encoded settings for the source block, copy them to the clipboard and paste them into the same field of the destination block. Check the Import settings checkbox for the destination block and save settings. Please note that the block name is not imported, what you put in the name field will be saved.

You can also copy complete Ad Inserter settings from one website to another. Go to settings tab (#) and click on the Import/Export icon next to the Save button. Select encoded settings for the source website, copy them to the clipboard and then paste them into the same field of the destination website. Check the Import settings checkbox for the destination website and save settings.

By default Ad Inserter exceptions on posts/pages are enabled only for administrators. You can define minimum user role for page/post Ad Inserter exceptions editing in Ad Inserter Settings (tab #).

Default Ad Inserter plugin processing order is 99999. It is used to specify the order in which the plugin functions are executed. Lower numbers correspond with earlier execution. You can change this value if you have problems with the processing order of other plugins.

WARNING: Text selection, Copy and Paste functions with the syntax highlighting editor do not work on mobile devices. If you need these functions you can temporarily swich to Simple editor using the checkbox above the code box.

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

Ratings

4.9 out of 5 stars

Support

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

Got something to say? Need help?

Compatibility

+
=
Not enough data

1 person says 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
50,2,1
100,2,2
100,2,2 100,1,1
100,1,1