Ad Rotator for WordPress and Non-WordPress Sites
This may be the most robust and reliable ad rotation software available. It is strong, sturdy, unlikely to break. Because it's not sophisticated, it's just straightforward code — very little that could break or hide bugs.
It's a simple concept. The software is succinctly written — only about 30 lines of PHP code.
No MySQL woes because none is used.
Your installation is protected by your own server logins. In other words, no extra software logins for hackers to crack.
Oh, and it will rotate any content that can be displayed on a web page. In spite of the software's name, it isn't restricted to only ads.
What I've written sounds like a sales spiel. But it's not. The software is free. It comes with the article.
The software installation is the same for both non‑WordPress and WordPress installations. But inserting the ad rotation into pages differs (one uses a line of PHP code; the other uses a shortcode). And what can be published is slightly different.
To add or remove ads for the rotator, upload or delete ad files in the directory containing the Ad Rotation Software.
Whether WordPress or non-Wordpress, the software needs to be installed before anything else. Let's go ahead and do that.
Installing the Ad Rotator Software
To install the Ad Rotator, follow these steps. (No software customization is required.)
-
Create a directory on your server for the Ad Rotator. It needs to be a directory exclusively for the Ad Rotator system. We'll call this the "ad rotator directory".
-
Copy the Ad Rotator source code. Save it as
AdRotate.php
and upload it to the ad rotator directory.<?php /* Ad Rotator Version 1.0 April 13, 2018 Will Bontrager Software LLC https://www.willmaster.com/ */ $SelfFileName = 'AdRotate.php'; $TrackFileName = 'AdRotate.txt'; chdir(__DIR__); $FileList = array(); foreach( glob('*') as $file ) { if( ! is_file($file) ) { continue; } $ta = explode('/',$file); $f = $ta[count($ta)-1]; if( $f == $SelfFileName ) { continue; } if( $f == $TrackFileName ) { continue; } $FileList[] = $file; } $FilesCount = count($FileList); if( $FilesCount < 1 ) { echo 'No ad file available.'; exit; } $NextFile = 1 + intval(@file_get_contents($TrackFileName)); if( $NextFile > ($FilesCount-1) ) { $NextFile = 0; } file_put_contents($TrackFileName,$NextFile); echo file_get_contents($FileList[$NextFile]); exit; ?>
-
Type the URL of
AdRotate.php
into your browser.If it responds with an error message, then something is wrong with the installation and will need to be corrected. Re-installing should do the trick. Re-copy the source code, saving it as a plain text file named
AdRotate.php
, and uploadAdRotate.php
into the ad rotator directory.On the other hand, if it responds with "No ad file available" (or with the content of an ad file you may have already uploaded into the directory), then it's working as it should.
-
The ad rotator directory should now contain a file named
AdRotate.txt
(the file Ad Rotator uses to keep track of the last ad that was loaded).However, if no file
AdRotate.txt
exists in the directory, thenAdRotate.php
was unable to create it. In that case, do these two steps.-
Create an empty file named
AdRotate.txt
and upload it into the ad rotator directory. -
Give file
AdRotate.txt
permissions 777.
-
The Ad Rotator is now installed.
To add ads to the rotator, upload ad files into the ad rotator directory. To delete files from the rotator, delete them from the ad rotator directory.
Publishable Content
Each ad is a separate file. Ads can be any content web pages can use, except one restriction for WordPress installations.
Content Type | Works On WordPress | Works on Non‑WordPress |
---|---|---|
JavaScript | Yes | Yes |
CSS | Yes | Yes |
PHP | No | Yes |
HTML* | Yes | Yes |
Plain text | Yes | Yes |
* Any valid HTML content — videos, images, forms, iframes, textual content, …
Rotating Ads on Non‑WordPress Sites
(Instructions for rotating ads on WordPress sites is in the next section.)
The web page must allow PHP code, a web page file with .php
file name extension.
Put this PHP code at the location of the page where you want the rotated ad to publish.
<?php include('http://example.com/place/AdRotate.php') ?>
Replace http://example.com/place/AdRotate.php
with the URL to your installation of AdRotate.php
in the ad rotator directory.
Rotating Ads on WordPress Sites
(Instructions for rotating ads on non‑WordPress sites is in the previous section.)
Install and activate Insert Here. (Instructions)
Put this shortcode at the place where you want the rotated ad to publish.
[insert_here url="http://example.com/place/AdRotate.php"]
Replace http://example.com/place/AdRotate.php
with the URL to your installation of AdRotate.php
in the ad rotator directory.
Niceties and Good-to-Know Bits
All ads are individual files in the ad rotator directory. The files contain content that web pages can publish. To publish an image, use an HTML img
tag, for example. And JavaScript between script
tags. A movie in a video
tag. And so forth.
The ad files may have any file name extension you wish, or no extension at all. For personal convenience, naming files with .html or .php extensions may help to recognize the kind of content they contain without manually opening the files.
If you want to insert plain text, put <div style="white-space:pre-wrap;">
immediately in front of the text and </div>
immediately after the text. It will provide line breaks without additional HTML markup.
Put new ads into the ad rotator directory from time to time to test how well they work.
Ad click statistics can be obtained by using links generated by Short URL V3. The link counts the click and redirects the browser to it's intended destination.
When click statistics are known, you can replace the low‑producing ads until you end up with only the hightest-producing.
Once you become familiar with the Ad Rotator, I think you'll appreciate how robust it is and how simple it is to use.
"Robust," however, is different than "sophisticated."
For automatic ad click testing — while publishing the more responsive ads more often and publishing the less responsive ads less often — use Carefree Ad Manager. That software also works with both WordPress and non-WordPress sites.
(This article first appeared with an issue of the Possibilities newsletter.)
Will Bontrager