Last Updated on April 20, 2020
Do you have a blog full of contextual advertising? Do you get some income from its archives?
If your answer is yes, then you might to know how to remove the ads from only one single post.
This is very useful if you write something that has a good potential of getting to the front page of social sites. In such cases, it is strongly advisable not to have lots of ads on the page, because your readers will appreciate more a clean, easy to read article, than one which is fragmented or surrounded by ads.
I encountered this advice given by Andy Hagans, an important link baiting expert, and I think he is right. This is what he says:
“A link bait piece is not about making $500 extra in AdSense. It’s about gaining RSS and newsletter subscribers, links and good branding. But you’re not going to be maximizing these benefits if you keep up the annoying banner ad up top, the left column AdSense block, and the large Chitika unit floating in the content. Everyone wants to link to clean, juicy information; no one wants to link to your ads. So when you’re launching your link bait, take down all your ads on the landing page for the “launch period” (usually 24-48 hours).”
I was never able to follow this advice, because I did not want to remove ads from my archives (besides, I never wrote such juicy link baiting pieces of information). The most common solution would be to use AdSense Deluxe plugin, and to set it not to show ads on that single post. Unfortunately, I don’t have the plugin installed, and with a blog having more than 200 posts, I would have had to edit every post in order to make them behave independently – this was definitely out of the question.
The solution came while reading a PHP book and wondering about why is it necessary to use
== whenever we want to define an equality relationship. Wouldn’t one single
= sign be enough?
A few rows later, I encountered the combination of
!= marks, with the meaning of a negation.
Of course! By applying this negation mark to a conditional clause, we can tell WordPress to put the ads on all posts, except one. This is the code:
<?php if( !is_single('Name of the post') ) : ?>
your ad code is here
<?php endif; ?>
This would translate in English like this: “if we are on a single post page, which is not entitled ‘Name of the post’, then display these ads”. The wondrous exclamation mark does the job.
You insert this code in the single post template file. Then, when you need to get rid of the ads from one post, you edit the template by replacing Name of the post with the actual name of your post (it also works if you put there the post number, or the post slug).
Do you know a better method for removing ads from a particular post in your WordPress blog?