Exclude adsense in contact us page etc.

Community Forums Forums General Discussion Exclude adsense in contact us page etc.

This topic is: not resolved

This topic contains 6 replies, has 2 voices, and was last updated by  braddalton 1 year, 3 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #62468

    Rick Adlam
    Participant
    Post count: 8

    Can you help?
    I am building a wordpress site on Generate, in a sub-directory till I know what I am doing. I will then transfer the site into the root of an old HTML site.
    I have put adsense code in the Generate child theme using Simple Hooks, at
    genesis_before_content_sidebar_wrap Hook,
    genesis_after_content_sidebar_wrap Hook and
    genesis_after_post_title Hook

    It works well.

    Now I want to exclude all this code from these pages:
    ‘ Contact Us’, ‘About Us’ Guest Writers’, ‘Submit Articles’, ‘Self Promotion’
    How do I write an array to exclude ads from these pages, and where do I put it?

    Any help would be appreciated.
    Rick Adlam

    http://www.mrmortgage.com.au/wordpress/
    #62494

    braddalton
    Participant
    Post count: 10679

    What code did you put in Simple Hooks?

    Try this http://designsbynickthegeek.com/tutorials/conditional-page-content

    And add an array with conditional tag
    [php]
    is_page( array( 42, 54, 6 ) )
    [/php]

    Ref: http://codex.wordpress.org/Conditional_Tags

    Or:

    I would use this in your child themes functions file:

    That way you could use an Adsense plugin if needed.

    Replace the pages names ‘ Contact Us’, ‘About Us’ Guest Writers’, ‘Submit Articles’, ‘Self Promotion’

    With page i.d’s which you can grab using Firebug or from your source code.

    Change the hook position if needed. HTML 5 or XHTML hooks


    #62574

    Rick Adlam
    Participant
    Post count: 8

    I put the Adsense code, and nothing else in Simple hooks.

    #62582

    Rick Adlam
    Participant
    Post count: 8

    Thanks Brad.
    In each hook, I tried to wrap the adsense code with this array, like this:

    <?php
    if( !is_page( array(‘Privacy Policy’, ‘Contact Us’, ‘About Us’, Guest Writers’, ‘Submit Articles’, ‘Self Promotion’,) ) )
    ; ?>
    I PUT MY ADSENSE CODE HERE

    <?php endif
    ; ?>

    I got this error

    Parse error: syntax error, unexpected T_STRING, expecting ‘)’ in /home/mrmortga/public_html/wordpress/wp-content/plugins/genesis-simple-hooks/plugin.php(123) : eval()’d code on line 1

    #62607

    braddalton
    Participant
    Post count: 10679

    That’s why i suggested you use the page i.d’s rather than the page names as they don’t always work.

    The i.d works better than the slug as well.

    You also don’t need the single quotes.


    #62700

    Rick Adlam
    Participant
    Post count: 8

    Thanks Brad,
    This is the code that worked.

    <?php
    if (!is_page( array ( 33, 51, 61, 75, 77, 78, 80, 81, 84)) ) { ?>
    ADSENSE CODE GOES HERE
    <?php }
    ?>

    I left the footer ads on all pages, but excluded the ‘genesis_before_content_sidebar_wrap’ Hook “banner ad” and the ‘genesis_after_post_title’ Hook “banner ad”, from only the pages specified.
    Lovely.

    #62794

    braddalton
    Participant
    Post count: 10679

    Good job Rick. Thanks for sharing your simple solution.


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

You must be logged in to reply to this topic.