• <?php if (!is_page('Contact Us')) { ?>
    ---ADSENSE CODE)
    <?php } ?>

    So I have 4 pages I dont want adsense showing, at the moment I can only add the “contact us” page for adsense not to show.

    I have another 3 pages I want to hide adsense on, how do I work this code?

    I tried doing

    <?php if (!is_page('Contact Us', 'checkout')) { ?>

    but that didnt work

    thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • The is_page() function only takes one argument, so trying to give it two won’t work, no matter how much you want it to. ??

    To use it with multiple pages, you’d need to do it like this:

    <?php if (!is_page('Contact Us') && !is_page('checkout')) { ?>

    That’s for two pages, but you can add in more as they are needed.

    Thread Starter harvie316

    (@harvie316)

    <?php if (!is_page('Contact Us') && !is_page(‘Privacy policy') && !is_page('checkout')) { ?>

    that is the code im using but then when i click on the pages blocked i get a syntax error, have i made a mistake somewhere

    Parse error: syntax error, unexpected T_STRING in /var/sites/w/example.net/public_html/wp-content/themes/comet/header.php on line 184

    The problem only comes up when I cut-and-paste into my editor, so it’s not a shock that you’re seeing something strange there.

    The problem is is_page('Privacy Policy'). The first ‘ in there is not a ‘. It’s a special character like a backtick, and that’s not valid in that context. Go back and change that and it should work.

    Thread Starter harvie316

    (@harvie316)

    wonderful, it all worked like a charm. I noted the words are case senstive as well. Thank you very much!

    I tried to use the same code on my widget ad sense. ahhhhh how do I do this.

    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!-- box -->
    <ins class="adsbygoogle"
         style="display:inline-block;width:300px;height:250px"
         data-ad-client="ca-pub-xxxxxxx"
         data-ad-slot="xxxxxxx"></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>

    It works exactly the same way. You just place your HTML code inside the if() statement. That’s all there is to it.

    Thread Starter harvie316

    (@harvie316)

    If()? sorry i am very new to all this coding ??

    <?php if (...) { ?>
       Your content goes in here
    <?php } ?>

    You had it right back in your first post. ??

    your code in just remaining array….

    <?php if( !is_page( array( Contact Us, ‘Privacy policy’, ‘checkout’ ) )){
    // your code
    }
    ?>

    you can pass id post_name and also post_title

    <?php is_page( array( 42, 'about-me', 'Contact' ) ); ?>

    // Returns true when the Pages displayed is either post ID 42, or post_name “about-me”, or post_title “Contact”.

    Thread Starter harvie316

    (@harvie316)

    <?php if (!is_page('Contact Us') && !is_page('Privacy Policy') && !is_page('Welcome to Checkout')) { ?>
    
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!-- box -->
    <ins class="adsbygoogle"
         style="display:inline-block;width:300px;height:250px"
         data-ad-client="ca-pub-xxxx"
         data-ad-slot="xxxx"></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
    <?php } ?>

    Thanks for the help guys, not managed to get it working yet for the widget. Any ideas on where I went wrong?

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘I need help with this php code’ is closed to new replies.