WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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

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

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

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

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

Your Answer


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.