June 11th, 2008
Hiding Advertisements For Single Posts
There are many plugins which are useful when it comes to displaying ads to your visitors but there are only a few of them which allow you to determine to whom and when you should. does help you to determine to whom and when you should display advertisements, though, there is a limitation with the plugin as it does not allow you to control the ads shown on single post level.
In this post we will talk about the quick and easy way to hide advertisements for any particular post by making some minor changes to your theme.
The Condition To Skip Advertisements For Single Posts
Talking about conditions whatever you do there is always a condition under which you perform any action. We will use a similar logic and create conditions under which the advertisements should not be displayed for certain posts.
The condition we will be using is quite simple and will fulfill the following statement, ” if something happens do this otherwise do something else”.
This can be simplified into lay terms as “if you are hungry buy a burger” “else don’t buy a burger”. As you can see the conditions you apply are quite simple and pertain to you to doing some kind of activity under different conditions.
The Code To Skip Advertisements In Single Posts
To skip advertisements for single posts you will have to manually edit the file “single.php” of your current WordPress theme. I recommend you edit your theme through the WordPress Admin Panel since it will help you catch any errors and save you a lot of trouble.
Once you have opened the single.php navigate to the place where you have placed the advertisements and change the code within the from;
…………
Your Advertisement Code
…………
to;
if(get_the_ID() != xx) {
…………
Your Advertisement Code
…………
}
Replace xx with the post id for the post which you do not want to show advertisements for. You can also skip multiple posts from displaying advertisements by adding the OR condition in the following way;
if(get_the_ID() != xx || get_the_ID() != xx) {
…………
Your Advertisement Code
…………
}
For those who are unaware of programming “||” represents OR in programming language and if you are curious AND is represented by “&&”.
How do you get the IDs of the posts you want to Skip Advertisements for?
To find the IDs for the posts you want to skip advertisements for, you will need to login to your WordPress administration panel and navigate to the Manage option. Once there find the post you want to skip the advertisement for and hover over it, you should see the ID of the post in your status bar. Check the screenshot below;

If you do not see the id in the status bar you can find out the ID by clicking on the post and going into edit mode where you will see the ID for the post in the URL.
![]()
Once you make the changes to your advertisements they will not display for the posts you chose to skip.
If you do have any questions feel free to ask them in the comments and I would be more than happy to answer them.
Note: This trick will not work if you use external plugins to display your ads and is only valid when you display ads by hard coding them into your themes.
Related CMS news:
Leave a Reply