Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to create a condition in Wordpress that only calls the wp_head() on all pages except for the "About Us" page and "News Articles" pages. Here's the code:

<?php if (!is_page('about-us') || !is_page('news-articles')) {wp_head();}?>

It seems to work great when I only use the command for one of the pages, but using an operator seems to mess things up. In some cases the pages load correctly, but the desired results are not happening. I've also double-checked to make sure that I'm referencing the pages correctly, and I'm confident that I am.

share|improve this question
add comment

migrated from stackoverflow.com Apr 26 '12 at 16:44

This question came from our site for professional and enthusiast programmers.

4 Answers

up vote 3 down vote accepted

You should be using the "AND" operator, not "OR"

<?php if (!is_page('about-us') && !is_page('news-articles')) {wp_head();}?> 

Because you want to display the WP head only if both conditions are true.

share|improve this answer
add comment

Rather than an or || you need an and &&.

<?php if (!is_page('about-us') && !is_page('news-articles')) {wp_head();}?>

Otherwise, one or the other condition is always true. If it isn't about-us, OR it isn't news-articles, this still leaves the possibility in each case that it is the other, while still satisfying the condition. Instead by using a logical AND, you specify that it isn't about-us and also isn't news-articles.

share|improve this answer
add comment

Well, look at what you're saying.

If it is not the "About Us" page, or if it is not the "News Articles" page...

So, let's say you're on the "About Us" page. Obviously "not on About Us" is false, but just as obviously "not on News Articles" page is true.

In fact, no matter what page you're on, at least one of the conditions will be true, and therefore the entire OR-combined if statement is true.

Use && instead.

share|improve this answer
add comment

All the others are correct of course, but if you really like your OR you can apply a bit of logic (!x&&!x === !(x||x)):

<?php if (!(is_page('about-us') || is_page('news-articles'))) {wp_head();}?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.