A simple question regarding adsense in action hooks

  • Ali


    I recently added an adsense banner on the graphene_after_post_content action hook. To my surprise, the homepage also displays the ads. I want the ads to appear only in the post’s page and not in the home page. How do I do this?


    Kenneth John Odle


    I did exactly the same thing and had the same issue. I wrote a tutorial for it, which you can rad read here:


    I mention a couple of different ways to handle it; you can choose what works for you.

    Good luck,




    Hi im having a problem using your procedure. It seems to work with other codes but for some reason when I use my adsense code it doesnt work. Why is that? is there any other way to do this? thanks



    Ken’s post should work for you. It’s the if statement that is determining whether or not to display on the homepage. The code within the statement should all be treated the same.

    Did you use a PHP widget? Did you use the IF statement?

    Can you post the code you used into http://www.pastebin.com and provide a link back here for us to look at?



    Hi! I did use the PHP widget. Here’s the code:




    Here’s the error I see when I use that code:

    Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’ in /home/pcpinoyc/public_html/wp-content/plugins/wp-php-widget/wp-php-widget.php(52) : eval()’d code on line 6


    Kenneth John Odle


    You need to escape all the quotation marks in your echo statement. Just put a “” in front of them.



    Hi can you help me out? I have no idea how to do that. Is there some tutorial on that on the internet? it will be greatly appreciated thanks!



    Give this one a try:





    You could also begin the function with if (!is_front_page()) {YOUR CODE}

    This reads “If it is NOT front page, then execute the code. The exclamation point is used for NOT. This helps with not needing an ELSE code; and is just a little “cleaner”.


    Kenneth John Odle



    Hi can you help me out? I have no idea how to do that.


    Just put a “” in front of them.


    Is there some tutorial on that on the internet?



    read part 5 (the last bullet point)– it’s buried in there somewhere. You can also try this one, which is far better than anything I found on the PHP manual.


    I did figure out there was a better way to implement that code, but I used is_single() which works on posts, but not pages. But it keeps it off archives. Not sure of something that does posts and pages, but nothing else. Probably need an AND statement in there somewhere.



    @ Ken,

    Thanks for that.

    This has been a big part of what I’ve been working on recently; understanding all the different wordpress conditional statements.


    Kenneth John Odle


    Josh — yeah, there are tons of those, and because they can be used in so many different ways, it takes time to figure them all out. It’s happy fun time when you finally get the one you need to do what you want.


    I looked at this again:

    it’s buried in there somewhere. You can also try this one,

    It is buried in there. I’ve highlighted this point to make it more obvious, and added the link I include above. You really need to know this, because a single unescaped quotation mark gives you the error you got above, which means no one can read your blog.



    thanks for the help guys! you’ve been both awesome. Got it working well.

Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.