Hi everyone, I started a WordPress blog and added AdSense to pages. I just edited the page.php page with the adsense code and its fine. But there are a few pages where I want no AdSense to be displayed. Is there a little piece of code to add so the AdSense code is excluded from these pages ? Thank you.
Pages I write when you select write->pages, not posts. I have AdSense on all of them, by editing the page.php, there are just 2 or 3 that I don't want ads on.
You need to add adsense in singlepost.php pagetemplate.php index.php By this only,you can get the ads in all the pages.
I already have AdSense on all the pages (pages only), there are just some pages I don't want ads on. I will try that, Thanks !
Well the plugin don't do what I want, so again I'll expose the problem, it is already written in the first post but it seems everyone give me solutions to add AdSense to every page. This is not what I ask. I have edited the page.php file so every page have AdSense ads on. But there are a few pages I'd like no ads on. So is there a way to "exclude" the code from these page, like some conditional tags or something ? Thanks.
Nopes,there is no way for it.. You can only recode the template make it as a separate page and then exclude the ad codes from it.
By Pages do you mean Particular Posts. There is certainly ways to do this. It really depends on what you want. If you are talking about particular posts then you could use custom fields to do this easily, however I need more information on exactly what you are looking to remove the ads from (certain posts/404 pages/etc..)
Oh I see now well what you could do is something like the following: Wherever the Adsense code is placed inside the template you replace with the following: <?php if($hasadsense !== '') { ?> ADSENSE CODE HERE <?php } else { echo ''; } ?> OK Then on the sametemplate page where the Ad appears (e.g page.php) Find: <?php if (have_posts()) : while (have_posts()) : the_post(); ?> Replace this with: <?php if (have_posts()) : while (have_posts()) : the_post(); $hasadsense = get_post_meta($post->ID, 'Adsense', $single = true); ?> OK after making these two changes resave the template file and re-upload it. Now hopefully, whenever you are writing a page that you want to show the AD on you would go to the Custom Fields Option, Type in a key of Adsense and a value of True.
That works exactly how I wanted. Thanks a lot. For those who ask why I would want no ads on some pages, this is because they have other offers on them. AdSense could make them leave the page and miss these, while I have AdSense on page where there is only content. Thanks again wd_2k6. This thread can be closed now.