A simple question regarding adsense in action hooks

  • Ali

    #2296

    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?

    Mod

    Kenneth John Odle

    #19648

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

    http://blog.kjodle.net/2011/11/04/graphene-action-hook-widgets-an-easy-way-to-modify-your-blog/

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

    Good luck,

    Ken

    alrwebber

    #19649

    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

    Josh

    #19650

    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?

    alrwebber

    #19651

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

    http://pastebin.com/4dSU3cAw

    alrwebber

    #19652

    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

    Mod

    Kenneth John Odle

    #19653

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

    alrwebber

    #19654

    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!

    Josh

    #19655

    Give this one a try:

    http://pastebin.com/xMbQehVx

    Josh

    #19656

    FYI:

    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”.

    Mod

    Kenneth John Odle

    #19657

    Q:

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

    A:

    Just put a “” in front of them.

    Q:

    Is there some tutorial on that on the internet?

    A:

    http://blog.kjodle.net/2011/11/04/graphene-action-hook-widgets-an-easy-way-to-modify-your-blog/#Bonus_A_Little_PHP_Goes_a_Long_Way

    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.

    @Josh

    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.

    Josh

    #19658

    @ 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.

    Mod

    Kenneth John Odle

    #19659

    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.

    @alrwebber

    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.

    alrwebber

    #19660

    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.