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