Smart Ads WordPress Plugin
| Author: | John Kolbert |
|---|---|
| Version: | 1.2 |
| Last Update: | May 11, 2008 |
| Compatibility: | 2.3+, 2.5+, others not tested |
| Description: | Automatically add advertisements to the beginning and end of posts based on the post length, age of post, category, or blog member status. |
| WP-Extend: | Official Listing at WordPress.org |
Downloaded 747 times from this page ![]() |
- Show ads above and below post content automatically
- Only show ads on single.php or page.php, not homepage
- Limit ad visibility by post word count
- Limit ad visibility by post age
- Limit ad visibility by category
- Selectively disable ads on a post-by-post basis
- Disable top ad if post begins with an image NEW!
- Disable all ads for registered blog members
- Add custom ads to posts or pages by selecting to type
<!-smartads->or{smartads}(for those who use visual editors) NEW! - Limit custom ads to be shown on only single post view or enable them on the homepage
- Built for WordPress 2.5!
Smart Ads automatically, yet intelligently inserts advertisements like Google’s Adsense above and below your post content. These advertisements are only visible when viewing a single post (single.php). Since it doesn’t make sense to fill small posts with ads, users can set a “Wordcount” minimum for their advertisements. Smart Ads will only insert advertisements into posts that meet or exceed the desired Wordcount. Do you start your posts with an image? You can chose to disable the top ad if your post has an image tag (<img...) in the first number of characters (you set the limit)! Also, to ensure that new content remains fresh, users can chose to only place ads on posts that are over a certain amount of days old. Advertisements can be manually disabled on a post-by-post basis while writing a post, for entire categories, or for registered blog members.
Users can also insert custom ads into their posts by chosing to inserting <!-smartads-> or {smartads} into their post text. You chose which method you’ll use in the “Options” area of the plugin. This allows bloggers who use their visual editors complete functinoality (some were having trouble with the HTML comment). Custom ads are not affected by the Wordcount or date minimum requirements and can toggled to be shown on the index page or only shown when in single post view.
| 1. | Download smartads.zip and unzip it. |
|---|---|
| 2. | Before uploading the folder, change yourads.php.txt to yourads.php. This prevents automatic upgrades from overwriting your file in the future. |
| 3. | Next, open "yourads.php" and paste your desired advertising code into the three indicated areas. yourads.php contains three variables which house your code data: $topad, $bottomad, and $customad. Sample data is provided as an example of how to paste your code. Replace the sample data by simply highlighting it and pasting your advertising code over it. Enter your ad code into the the other two variables to match. |
| 4. | Because we’re working with PHP data, you may have to “escape” your advertising code if it contains any single quotes ( ‘ ). Escaping means simply placing a forward slash before the single quote. So if the original sentence was: “Hello, I’m “hungry” didn’t you know?” You would escape it to look like the following: “Hello, I\’m “hungry” didn\’t you know?”. If your code doesn’t contain single quotes then this isn’t necessary. |
| 5. | Upload the plugin folder containing both files to wp-content/plugins/ and activate from the Plugin administrative menu. |
Smart Ads is now fully compatible with the WordPress 2.5 automatic upgrade feature. Your advertising code will not be overwritten. If you chose not to use the automatic upgrade feature, disable the Smart Ads plugin, upload your newly downloadedsmartads.php file to your current smartads folder, and reactivate the plugin.

| Show Custom ads on Homepage | The custom ads are called by placing <!-smartads-> in your post where you want the ad to appear. This setting allows you to show these custom ads on the homepage or only on the single post view. |
|---|---|
| Custom ads notation | You can chose to use one of two notations to display custom ads in your posts and pages. <!-smartads-> is recommended because if you deactivate the plugin the snippet hides itself becaue its an HTML comment (and thus not visualized by your browser). However, bloggers who use the visual editor may have some problems with WordPress removing this code. Thus you can use {smartads}, which will do the same thing but won’t degrade as nicely if you deactivate the plugin. |
| Minimum Post Word Count | Top and Bottom and will only appear on posts that meet or exceed the number of words listed here. This is to avoid short posts being overwhelmed with advertisements. A setting of 0 disables this feature. |
| Only show ads on posts older then | the amount of days you chose. This keeps fresh content ad free while monetizing older articles. A setting of 0 disables this feature. |
| Top, Bottom, and Custom Ad | The code that you pasted into “yourads.php” is dispalyed here for informative purposes only. |
| Category Exclusions | List the ID of categories that that you don’t want ads to be displayed in. Category IDs must be listed with a comma and a space inbetween them, such as: 12, 3, 15, 1, etc. This does not affect custom ad visibility. |
| Disable Ads For Registered Members | If selected, all ads will be disabled for readers who are logged into your blog. This includes the admin and all subscribers. |
| Hide per post options box | Ads can be disabled on a per-post basis. However, some users have said they would like to hide this options box in the write-post screen entirely. This does just that without affecting any of your posts options (posts with ads disabled will still have them disabled). |
Why don’t some of my Adsense ads showup?
Google Adsense plolicy states that a maximum of three ad units may be placed on a single page. Make sure you don’t exceed this. If this isn’t your problem, make sure you have correctly pasted your adsense code into “yourads.php”.
How can I format the CSS around my ads (such as padding, margin, etc)?
Formatting the space above and below your ads is very simple. Open yourads.php and simply surround your advertising code with the html you want. You can add <div> tags and format them with CSS. The styling will apply to all ads of that type.
I want to place a large square ad at the beginning of every post, but the post content doesn’t wrap around the ad. How can I fix this?
This problem can be fixed with a little CSS tweaking. As in the question above, open yourads.php and surround your $topad code with the following CSS styling:
Code:
1 2 3 | <div style="display: block; float: left; margin: 0px 10px 0px 0px;"> Your Ad Code Here </div> |
How do I insert my own ad code?
To insert your own ad code open yourads.php in a text editor, such as notepad, or code editor. In this file are three variable names “$topad”, “$bottomad”, and “$customad”. Each represents the top, bottom, and custom ads that will be inserted into your posts. Your code should be copied so it looks like the code below:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | //This advertisement will appear above your post content. You can surround it by any HTML you like (as shown). $topad = ' <div style="display:block;float:left;margin: 0px 10px 0px 0px;"> <script type="text/javascript"><!-- google_ad_client = "pub-xxxxxx"; /* 250x250, created 4/9/08 */ google_ad_slot = "xxxxxx"; google_ad_width = 250; google_ad_height = 250; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div> '; //leave this line |
How do I disable the advertisements just for the post I’m writing?
When writing or editing your post an options box will be visible below the post editing box with a checkbox that, if checked, will disable ads for that post only. This option only affects the automatic insertion of top and bottom ads. Custom ads will still appear if you include their tag.
- Version 1.2: released on May 11, 2008
- added ability to hide top ad if post begins with an image, added an aditional custom ad notation, revamped the “write post” options box and provided a way of hiding it
- Version 1.1.2: released on April 16, 2008
- fixed critical error with Smart Ads interfering with RSS content
- Version 1.1.1: released on April 15, 2008
- added ability to disable ads for all registered users
- added ability to exclude ads for entire categories
- Version 1.0.1: primary release on April 10, 2008
Copyright © 2008 by John Kolbert (aka Simply-Basic.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Thank you to all those who have submitted feedback and helped improve the Smart Ads Plugin. A special thanks goes out to Michael for sending many of the feature requests that helped make Smart Ads..well, smart!




Love this simple, yet highly useful plugin! And I already have a wishlist for future development. Here is my list:
* Disable Ads entirely when registered users view this website.
* List of categories on which not to show ads (eg. Asides)
That’s it. Otherwise everything is fine for me ;-)
Michael’s last blog post..Marsedit, Markdown und Wordpress
Me again: If you do not enter code for one of the plugins, WP adds a BR-tag instead… Another thing to future development.
Michael’s last blog post..Marsedit, Markdown und Wordpress
Oh, there is something more: I am using a plugin that surrounds the written text with the google_adsection_start and -end tags. This is ignored by the smartads-plugin.
To my first comment: I just checked whether there is a br-tag inserted, IF there is an ad shown and… yes, there is! Can you somehow make this BR-tag disappear?
Michael’s last blog post..Marsedit, Markdown und Wordpress
@Michael I’m glad you like the plugin! As far as your wish list those sound like excellent things to add. Let me just clarify a few things.
You want a
<br />tag added if you don’t add code data to one of the variables? May I ask why? If no data is entered the plugin is set to display the content as you originally entered it.You say the plugin ignores the google_adsection_start or _end tags. If I’m not mistaken aren’t those tags used to target the adds to be more relevant, not for actual placement of the ads? I could easily add placement control tags so you could determine where the opening and closing ads would be placed if you wanted them somewhere other then before and after the content.
As for disabling for registered users and category exclusions, those are great ideas! I’ll look into implementing those into the next release.
That br tag you are talking about is actually hard-coded into the plugin. I’m planning on removing it from the next release since you can control the CSS of the ads yourself. If you want to manually edit it out yourself, open smartads.php and edit line 214 (approx.) by removing the
"<br />" .Thanks for the suggestions!
Woops, and there goes the answers:
(First thing: Can’t you put the comment preview below the actual comment-textbox? This is somehow annoying: If you paste a bunch of text, it jumps around all the time and I have to scroll up and down to see your comment…)
> You want a tag added if you don’t add code data to one of the variables? May I ask why? If no data is entered the plugin is set to display the content as you originally entered it.
No, no, no. It’s the br-tag that I don’t want! (With “another thing to future development I mean to remove this br!)
> You say the plugin ignores the google_adsection_start or _end tags. If I’m not mistaken aren’t those tags used to target the adds to be more relevant, not for actual placement of the ads? I could easily add placement control tags so you could determine where the opening and closing ads would be placed if you wanted them somewhere other then before and after the content.
Sure, my mistake!
> As for disabling for registered users and category exclusions, those are great ideas! I’ll look into implementing those into the next release.
Great!
> That br tag you are talking about is actually hard-coded into the plugin. I’m planning on removing it from the next release since you can control the CSS of the ads yourself. If you want to manually edit it out yourself, open smartads.php and edit line 214 (approx.) by removing the “”
It was exactly 214. And it is gone now! (Why did you actually put it inside?)
Michael’s last blog post..Marsedit, Markdown und Wordpress
Version 1.1.1 was just released adding a few new features.
How does this plugin compare to the Adman plugin that sounds exactly the same?
Ken Savage’s last blog post..Good Times at Tonights Celtics Game
@Ken Savage Great question! I’ve actually never heard of Adman before, so thanks for pointing it out. It looks like a good plugin. The basis for the two plugins, like many Adsense-enhancing plugins, is just to make ad placement automated. These two plugins both ad ads to the beginning and end of a post and let you insert your custom ad wherever you want.
So what’s the difference? The difference here is in the bells and whistles. Aside from simply disabling ads on a per post basis, Adman doesn’t have any configurations while Smart Ads comes loaded with quite a few. Just check the “Features at a Glance” section at the top of the page. With Smart Ads you can precicely control which posts actually get ads on them rather then blind placement on every post (such as Wordcount, post date, category, logged in users, etc).
AdMan also uses some deprecated WordPress code that could use some updating. I wrote Smart Ads on and for WordPress 2.5. This plugin was actually written for my own use because I didn’t see any plugins that gave me the control I needed. After a while I decided to release it to the public. Thanks for pointing out the similarity!
thx John for replaying so quick. I’m downloading now and I’ll check it out. If it lives up to what I’ve heard so far I’ll do a review on my site.
thx again
Ken Savage’s last blog post..An Easy Way To Improve Your Online Reputation
@Ken Savage I hope you enjoy the plugin! Let me know if you have any improvement suggestions (bug fixes, feature wish-list, whatever).
Just so everyone knows, if you have any feature requests feel free to leave them in the comments here. I’ve added several features as a direct result of user comments and emails.
In the next version of smart ads look for the ability to disable the top ad automatically if the post has an image in the first xx characters (you an set the limit). Also the per-post options box has been redesigned to take up less real estate and can be shown/hidden based on user preference. I’m going to hold off releasing it for three or four weeks so I don’t keep flooding everyone with new versions. So if you’ve got a feature you’d like to see, now’s the time to let me know!
Great plugins. Good developments. Many thanks to John Kolbert. My wishlist is how about ad from others ads, like adbrite, text-link-ads.
I think you very smart for answer and building others ads plugin.
Great Jobs John Kolbert. Thanks for all
Hey syarifudin, I don’t see your problem: Since you insert whatever code you want to have in “yourads.php”, you can use adsense, adbrite, tla, whatever…
Michael’s last blog post..Cut the crap!
Hey Michael. thanks. I would report bug for you later.
@ari syarifudin Michael is correct, you can use this plugin with any ad system you want. You just need to paste your code into “yourads.php”. I just use Adsense as an example because it’s one of the most popular. Just make sure you “escape” your ad code with forward slashes as explained above in “Installation”.
thanks for this plug-in… i couldn’t figure it out first… it wouldn’t post any ad… i thought i tried everything until i filled in all the boxes on the options page :)
This is fantastic. Have you ever considered looking at more WPMU compatability? It would require creating the ability for the blog admin to edit his ads from the dashboard rather than editing the source code of a file.
For now though, I can still use this under MU for the main admin blog, this is great!
@Radio: I’m glad you enjoy the plugin! I’ve not worked with WPMU much, but I’ll look into it and see what I can come up with for the next release.
Hi…
Before I implement this plugin, I just had one question…
Can one put ads just at the bottom of the post with this plugin or is it hard-coded to be below AND above the single posts - period? Thanx…
The GTLs last blog post..Washington Post: Pentagon Has Successfully, Intentionally, De-Emphasized The Passing Of Our War Heros
Hey, GTL! You can define everything. It is not hard-coded.
@The GTL: Right, if you don’t want ads to show up before your post ever, just don’t enter your advertising code in
yourads.phpfor$topad.Awesome, guys… thanks. I’ll give it a whirl because I tried that other one and I’m not completely impressed with it. Thanx again :-)
I would like the ads to show at a specific location, is there a php code that I can manually embed, or a place where I can specify exactly where “bottom” is?
Thank you! :D
@noobcook: Currently there isn’t a way to manually define where the “top” or “bottom” of a post is, though this would be an interesting feature. I’ve thought about making it so Smart Ads will place ads at the top and bottom of an article unless for that post you manually tell it to place them else where, in which case it would place the ads in you post where you tell it to. Would that be what you are looking for?
Hi i have tried it in my blog, it works fine with google adsense, but with custom ads some problem; in the editor (html mode, not visual) when i write:
<!-smartads->when i save it, it automatically reformat it as:
so it put a space between < and !
so when i browse the article it doesnt show my code specified in yourads.php but just the
Where im wrong?
thanks,
Simone Italy
Simones last blog post..Un esempio pratico di uso applicazioni web opensource
Do you have the visual editor enabled at all (you switch back and forth between visual and HTML views) or is it disabled entirely? I disable mine entirely. What happens is WordPress reformats any HTML it doesn’t like when the Visual editor is enabled as you switch between the two views. The HTML used to trigger the custom ad code is technically an HTML comment: it’s not interpreted by the browser nor displayed on the screen, only in the source of the file. It is designed this way so that if you disable the plugin you don’t have to go back through old posts and remove the code.
In the next release of the plugin (in the next week) it will see about possibly introducing another way to include the custom code, for instance I could make it so [smartads] calls the custom code as does
<!-smartads->. That means people who need the visual editor could use it, but if they ever got rid of the plugin you would have to go through every post and delete it.Is it possible to have the text wrap around the ad at the top of the posting?
Yes, it can be done via CSS styling. Just place the style code around your ad in yourads.php. Such as:
Thanks John. That is the css code that I am using but the text only flows down the right side and along the bottom as you can see if you visit http://www.ricward.com..
I was trying to get the code flowing from above as well.
Richards last blog post..The Brain That Changes Itself
Oh, I forgot to say that your code is very sweet…so easy to implement! Thank you so much!
Richards last blog post..The Brain That Changes Itself
@Richard: Sorry, looks like I mis-read your question. Off the top of my head I don’t think that you can get the text to wrap around the top of the ad (for the top ad, at least). The plugin appends your advertising code so that it appears before your post text. So I don’t know that you could get text to flow on top of the ad. If you want less space between your ad and the post title you could try giving it a negative top margin, such as
margin-top: -10px;If you are talking about the custom ad you just need to mess with the CSS styling (margin and padding) until you get it to look the way you want. Sorry, hope that helps!
Hello John,
it works like a charm!
Thanks so much ;-)
all the best
Gianni
gidibaos last blog post..Exec-PHP in italiano
Hi John, some features for the next release if i could suggest:
yourads.php directly directed on admin interface
automatic advertising after x posts in the loop (so not only advertising on single pages)
Thanks, Simone Italy
Simones last blog post..Trackmania Nations Forever: gioco di auto free!
well if i could suggest another good next feature, to have multiple custom ads indentified by an ID, so then when wrinting it on posts, it will be: {smartads=1} {smartads=2} etc…
Simones last blog post..Nasce StreamingCountry
@Simone: Those are all excellent ideas. I’ll see what I can do for a future release. Thanks for taking time to comment!
Is it possible to insert and have ads show up in footer.php. Thus far I’ve not been able to get this to work. Do the have to be in a post box?
@John: No, sorry. Smart Ads is only for inserting ads into post or page content (via the post box). Sorry!
Nice plugin. had it working fine - but it somehow stoped showing the ads in my posts? Rather strangely the still show in pagess with the custom tag - I tested that in the posts but just see the tag.Any ideas John? Thanks.
Hmm, so only custom ads are showing in your posts? Does the bottom ad still show? Check the word count, category exclude, and age of post settings in the options menu and make sure you dont’ have those set to exclude ads from where you want it. If that doesn’t work let me know and I’ll dig into it more.
Hello John,
I have a question. With PHP v4.4.4 the plugin works fine. I’ve upgraded to PHP v5.2.2 and it stopped to display any ads!!!
Anyway, I’ve downgraded the PHP to 4.4.4 (for testing) and Smart Ads works again.
Any tip?
Thanks in advance
Gianni Diurno
gidibaos last blog post..Gravatar for You: Zodiac Package
@gidibao: Hmm, that’s very interesting. I’m nearly postitive I’m using 5.2.2 on my development server. Let me look into it further and I’ll get back to you.
John Kolberts last blog post..Email Protect RC1 WordPress Plugin
not showing at all :(
egis last blog post..Zeke & the popo
@gidibao: On my development server I use PHP 5.2.5 and Apache version 2.2.8. I downloaded PHP 5.2.2 and used it without any problems. Looking over the code there shouldn’t be any reason why there should be compatability issues between PHP 4 and 5 (though I didn’t want to downgrade my Apache version to test 4.4.4). Are you sure all your settings are enetered correctly in the Options menu? Is Smart Ads the only issue you noticed when switching PHP versions?
@egi: Nothing worked? Did you fill out any settings in the options menu? Did you convert yourads.php.txt into yourads.php and fill it with your advertising code?
it showed up now..
i think i’ve madde a mistake on the option page…
Thank you for your great plugin John
egis last blog post..Zeke & the popo
John - thanks for your kind reply. The Smart Ads settings are correct. I think it could be a problem of mine. I will check my server settings and any other issue through the weekend.
Thanks again
All the best
Gianni
gidibaos last blog post..Gravatar for You: Zodiac Package
where’s options page?
I tried everyting, but I still failed to find it!
@hyperlook: in WP 2.5 it’s under “Settings”->”Smart Ads”. In WP 2.3 it’s under “Options”->”Smart Ads”.
What version are you using?
the version is wordpress 2.51
under “Settings”, there are lot’s of other plugin’s options but none is for Smart Ads!
Thanks a lot for ur email!
It help me find the reason - maybe “smart ads” is conflict with another plugin “SEO Smart Links “,and after i disabled the latter ,it’s options come out!
Thank you for great job. it is nice plug-in.
Классно, штука полезная!
Hi John, i have encountered the same problem of Gidibao with the hosting of my wp blog, with php v4.4.4-8+etch6 the ads are showing, with php v5.2.0-8+etch11 they dont appear… the settings of smart-ads i see are ok on wp admin
Simone:
Hmm, I’m afraid I’m at a loss as to why this would be. The two of you are the only one’s who have had an issue. I’ve test all my plugins on PHP 5.2.6 and legacy PHP 4 versions without any problems. I’ve not been able to reproduce the issue you’re having here. Any other servers or local servers you could try it on and see if you get it to work there?
I’m having the same problem — ads are simply not showing. PHP v5.2.2 and Apache 2.2.(newest). SmartAds is activated and shows options correctly. Strange.
Correction: the ads ARE showing but for Firefox and not Safari!