How can I stop adsense appearing on certain posts/pages of my blog?

Discussion in 'AdSense' started by BuenosAires, Apr 26, 2007.

  1. #1
    I have a Wordpress blog where I have adsense in my home, archives, post and page templates, so that the ads appear on every single webpage in my blog.

    HOWEVER, I have a few posts and pages that I do not want the adsense to appear on, because I am selling other products/services on some pages and I do not want the adsense ads to prove a distraction.

    I can't remove the adsense code from my wordpress templates for posts or pages because I want adsense to continue appearing on the majority of them. Also I want to keep my adsense in my template code, and nowhere else (i.e. no adsense injection plug in suggestions please - and nor do i want to manually put the code on each post and page i need it on)

    So, is there anyway I can stop adsense ads from a particular post or page on my blog?

    Green rep for those with useful answers!
     
    BuenosAires, Apr 26, 2007 IP
  2. netjobs

    netjobs Banned

    Messages:
    1,442
    Likes Received:
    104
    Best Answers:
    0
    Trophy Points:
    0
  3. BuenosAires

    BuenosAires Peon

    Messages:
    159
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks, but... maybe i'm being stupid - i just can't see a solution to my problem from a quick look through that search (which i had already tried before)

    does anyone know a way to block adsense from appearing from a few particular pages on your website or wordpress blog???
     
    BuenosAires, Apr 26, 2007 IP
  4. Qryztufre

    Qryztufre Prominent Member

    Messages:
    6,071
    Likes Received:
    491
    Best Answers:
    0
    Trophy Points:
    300
    #4
    [​IMG]

    I think you were looking for the wrong terms ;) The check box "enables on individual posts" and I think you wanted to block on individual posts. Could be a matter of wording...could be this isn't what you wanted...
     
    Qryztufre, Apr 26, 2007 IP
  5. mooiness

    mooiness Peon

    Messages:
    409
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I don't think this plugin will help the OP. It sounds like he had hard-coded the Adsense code into the template files. If he had started using the Adsense Deluxe WP plugin from the start, then he wouldn't be having this problem.

    To the OP: unfortunately short of some PHP-trickery (which will be a pain to manage in the long run) you cannot selectively disable ads on certain pages only.

    A workaround may be to rework the placement of the Adsense ads so that they would work well with any additional custom ads which you might selectively add to certain posts.

    Good luck!
     
    mooiness, Apr 26, 2007 IP
  6. Grokodile

    Grokodile Peon

    Messages:
    425
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hmm, if the OP did this, in the PHP files...

    Then, I think they should certainly be able to look at the current URI and see if it is the same as the URI of a page they don't want to display adsense on. All you have to do is create the page, see what the URI ends up as, and then put in an if statement something like this:

    if ( $URI == 'not-here-1'
    ||   $URI == 'not-here-2' )
       ;
    else
       do_adsense();
    Code (markup):
    If the OP didn't edit the templates by hand, then I'm probably speaking in tongues... :D
     
    Grokodile, Apr 26, 2007 IP
    BuenosAires likes this.
  7. mooiness

    mooiness Peon

    Messages:
    409
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #7
    @Grokodile: he can do that but it'd be a MAJOR pain in the ass to maintain, going forward. :D
     
    mooiness, Apr 26, 2007 IP
  8. BuenosAires

    BuenosAires Peon

    Messages:
    159
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #8
    thanks grokodile, you are on th right track to helping me :) I edited the wordpress templates by hand to insert the full adsense code where I want.

    if I can put some PHP code in the templates, like you say, to stop the adsense appearing on certain pages/posts (at the moment, I only need it stopped on 3 or 4 URLs total), then that will not be difficult to maintain at all. in fact, that's exactly what I want! :)

    i'm going to test it now... though maybe i will need some more help if it doesn't work first time round ;)
     
    BuenosAires, Apr 27, 2007 IP
  9. BuenosAires

    BuenosAires Peon

    Messages:
    159
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Hi Grokodile,

    I tried pasting...


    if ( $URI == 'not-here-1'
    || $URI == 'not-here-2' )
    ;
    else
    do_adsense();​

    ...just before where the full adsense code is found in my template (obviously I changed the not-here-1 etc to my URLs where I don't want the ads to appear.

    However, all that happened was that the code pasted appeared as writing on my blog just above the adsense ad! i know i am being very stupid, but what exactly am I supposed to do.

    any more help will be greatly appreciated! :)
     
    BuenosAires, Apr 27, 2007 IP
  10. BuenosAires

    BuenosAires Peon

    Messages:
    159
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #10
    ok, i guess Grokodile was assuming maybe i knew how to play with PHP code a little better, and only put a part of the code for me to finish off... actually i'm new to PHP but i like to learn things by a little trial and error!

    using Grokodile's suggested code, and observing some other if code that i found elsewhere in my wordpress templates, I cobbled together the following:

    <?php if( $URI == 'this-is-a-url-string'
    || $URI == 'this-is-also-a-url-string' ) {
    '
    ';
    } else {
    'HERE IS MY FULL ADSENSE CODE';
    }?>​

    but it doesn't work. any idea, PHP experts, what i am doing wrong?
     
    BuenosAires, Apr 27, 2007 IP
  11. BuenosAires

    BuenosAires Peon

    Messages:
    159
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #11
    for the person that gave me red rep on this thread with the following note...

    "man your dumb, i feel sorry for you"

    ...remember, when you are calling someone dumb, it helps not to show your own stupidity through poor use of grammar ;)

    (PS - Grammar is easier than PHP. Especially when you are completely new to PHP, like I am)

    Oh, and the people over in the PHP subforum are now helping me out :)
     
    BuenosAires, Apr 27, 2007 IP
    Grokodile likes this.
  12. Qryztufre

    Qryztufre Prominent Member

    Messages:
    6,071
    Likes Received:
    491
    Best Answers:
    0
    Trophy Points:
    300
    #12
    classic!

    When you get the final answer please share it with us. It'll help anyone that happens along this thread in the future (should they be having the same problems).
    Q
     
    Qryztufre, Apr 27, 2007 IP
  13. Grokodile

    Grokodile Peon

    Messages:
    425
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I suspect the issue is that you are using the $URI variable as if it contains the URI, but it won't unless you put it there!

    You can do something like this...

    $URI=$_SERVER['REQUEST_URI'];

    P.S. I didn't notice your posts... it may have been a good idea to PM me if you want me to find the thread again... ;)
     
    Grokodile, Apr 30, 2007 IP
  14. Roseate

    Roseate Active Member

    Messages:
    220
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #14
    Oh! I am having the same problem :(

    I need to stop adsense from on of my categories,
    so the it won't appear when I open the posts on
    that category?!

    I am now using it at the top of the posts at my
    home page and single posts, I just need to remove
    it from posts in one category...Is that possible?

    Thanks,
    Roseate
     
    Roseate, Nov 28, 2007 IP