Thursday, July 8, 2010

TutZone- Tutorials, Design news and Inspiration

TutZone- Tutorials, Design news and Inspiration

Link to TutZone

How to Hide Advertisements for Single Posts

Posted: 08 Jul 2010 04:48 AM PDT


As in our previous tutorial, I showed you how to show your adsense to only Google visitors. In this tutorial you will learn how to hide advertisement for any particular post. This technique comes in handy if you publish many posts a day and want your regular readers not to get distracted by your ads, you can always show them up after a day is over or after a certain period of time.

Step by Step Tutorial:

Note: Do take backup of your theme before you try this.
This example supposes that your ad codes are added in single.php file. You can edit different file if your ad codes are added in some other file.

01. You need to know the ID of the Post on which you don’t want to display your ad. For determining it, you can check below link

02. Go to Appearance => Editor.
editor

03. Then choose single.php file from right hand side and go where you have added your ad code and change it to:
single.php
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.

03. You can also use this on multiple posts, just keep adding your Post ID’s in below pattern:

if(get_the_ID() != xx || get_the_ID() != xx) {

…………

Your Advertisement Code

…………

}

04. Save and you are done.

Scripts Sources:

That concludes this simple and useful tutorial. Hope you like it.

No comments:

Post a Comment