Putting ads on your WordPress site is quite a personal choice: for some it will be one of the first things you do, while others will resist it for a while. After quite a while of refusing to put ads on my site, I have finally decided to put up some ads that advertise my own services, not least to educate my readers that I do offer things like WordPress hosting packages and WordPress consulting services.
I created a few ads in the standard 125×125 and 468×60 sizes. The intention was to put the 468×60 ads at the bottom of the article, and the 125×125 ads at the beginning of the article. However, after trying that, I didn’t like how an ad was the first thing your eyes see when trying to read an article – the emphasis of my site is on informative WordPress tutorials, not the ads. So I wanted to set about moving it down the page slightly.
This seemed like a simple idea, but there was more to it. The standard call for displaying your WordPress content (the_content) is just a single line that automatically pulls the entire post from the database from beginning to end, so inserting something in the middle of it is not as easy as it sounds.
However, you can use the following code in place of your content call to enable you to place your ad code (or any other type of code) after a set number of paragraphs. So, open up your theme editor and open single.php for editing and look for the following line:
Now you’ll want to replace that with the following code snippet. Don’t worry about it’s apparent complexity – there’s only two simple variables in there that you will need to change:
In this example, the ad will be displayed after the second paragraph. This is as a result of the $show_after_p = 2 line near the top of the snippet. You can change this to another value to suit your needs.
The other thing you will need to change is the ad code itself. Two thirds of the way down, you will see a spot that says YOUR AD CODE GOES HERE. This is where you should place your AdSense or other code.
Since I wanted to use ads that were advertising my own sites, I went with an internal ad control plugin. After reading an article on DataFeedr Random Ads v2, it sounded like a perfect fit for my needs. You can use it with ad publishers’ codes (like AdSense or BuySellAds) and also sprinkle in your own ads.
All I needed to do was copy the PHP template code that Random Ads provided me and slot it into the snippet above and you can see the results for yourself.
Have you ever considered putting ads on your site? Where do you place them? Is this sort of solution a welcome relief to you?