WordPress Plugin: Insert Ad Code

I wanted a way to generate more revenue off my WordPress blog. A lot of sites use square ads embedded after the first couple of paragraphs of their articles, and I thought this would be perfect for my post pages, which don’t show the WordPress sidebar. But I couldn’t find a way to do it, so I wrote Insert Ad Code to do it for me.

Insert Ad Code is a pretty simple WP plugin: it inserts some HTML into your posts. It’s very easy to install and pretty easy to use.

Installation

To install Insert Ad Code, all you need to do is unzip or upload the insert_ad_code directory to your wp-content/plugins directory. Then activate it through the Plugins page of the site admin. That’s it, everything’s ready to go.

Using Insert Ad Code

Before you start using Insert Ad Code, you’ll need to have some kind of ad to display. I use the Openads Ad Server on my site, but you could also use Google AdSense or any other add server.

**Important Note:**Insert Ad Code does not rotate ads by itself. It inserts the same code every time its used. If you only have one advertiser at a time, this might be fine for you, otherwise, you’ll need to use some external program to rotate the ads.

For now, I’ll assume you’re using AdSense. Go get the AdSense code from Google. I recommend either a box ad (250×250) or some kind of horizontal ad (banner or half-banner, depending on your theme), since these will get inserted directly into the post.

For example, your code might look something like this:

<script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxxxxx";
//Inserted into Articles
google_ad_slot = "xxxxxxxxxxxxxxx";
google_ad_width = 250;
google_ad_height = 250;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>```

Copy the code for your ad and visit your WordPress Options page. Go to the Insert Ad Code options. Paste the code into the text box at the bottom. Click Update Options ».

Customizing Insert Ad Code

Now you have a couple of choices here. The first option (Enable Insert Ad Code) will turn the plugin on or off (turning it off does not disable it in WordPress). This makes it easy to stop inserting ads if you need to.

The second (Use <!–more–> or Custom Tag) and third (Custom Tag) options let you decide where Insert Ad Code will put the ads. The default option is to insert the ads right by the <!–more–> tag. You could also use a custom tag (I’d still recommend using an HTML comment, just in case you turn off Insert Ad Code later).

I use the <!–more–> tag for four reasons.

  1. I don’t want to break up very short posts with ads.
  2. I don’t want to go back and insert a new tag into all my old posts.
  3. I want the ads to appear once, after a couple of paragraphs, just like the <!–more–> tag.
  4. I want the tag to be easy to add via the WordPress editor.

If you do feel like using a custom tag just change the settings, include that tag in your posts, and watch the magic happen.

License

This plugin is “show me”-ware. If you decide to use it, please let me know so I can see my handiwork in action! Other than that, it’s GPL.

Download Insert Ad Code

Now that I’ve been talking it up so much, you probably want to download the plugin.

Update! You can now check Insert Ad Code from SVN to get the latest build.
svn://jamessocol.com/insert_ad_code/trunk

You can check out the tags directory for specific versions.

Feedback

Please leave a comment or email me if you use Insert Ad Code, or if you try to use it and hate it, or if it kills your dog. I’m not going to bring your dog back to life, but I’d love to hear your feedback.

Update (Again)! If you’d like to help me translate Insert Ad Code, version 1.1.0 and above contain .po files. If you’re bilingual, translate it and send me the .po and .mo files, and I’ll include them (with credit, of course!)