Shane Holmes
Shane Holmes

Reputation: 39

Using multiple OR in a If Statement in PHP

On our website (wordpress site)

I am trying to create a page and I am trying to remove some HTML from being implemented on some of the pages.

This code is from my header.php file

This is the current working code

<?php if(!Is_front_page() || !is_page('my-page-1') || !is_page('my-page-2')) : ?>
 <div class="breadcump1" style="margin-top: 50px">
   <div class="page-wrapper">
     <div class="page-body">
       <article id="post-814" class="post-814 page type-page status-publish hentry">
       <div class="container" >
         <?php if (function_exists('qt_custom_breadcrumbs')) qt_custom_breadcrumbs(); ?>
       </div>
       </article>
     </div>
   </div>
 </div>
<?php endif; ?>

Thecode above works. The html is not implemented on the home page. However, I also want to eliminate the code for two other pages (my-page-1 my-page-2)

<?php if(!Is_front_page() || !is_page('my-page-1') || !is_page('my-page-2')) : ?>

But, I cant seem to get it to work. What am I doing wrong with the ORs?

Thanx

Upvotes: 0

Views: 296

Answers (2)

George Pant
George Pant

Reputation: 2117

Since you do not want the html displayed in none of these pages you could just use && ( AND). I think it is more intuitive.

"If it is not front page AND is not 'my-page-1' AND is not 'my-page-2' show the page"

<?php if(!Is_front_page() && !is_page('my-page-1') && !is_page('my-page-2')) : ?>

Upvotes: 2

sbrbot
sbrbot

Reputation: 6447

Basics of logic !(A || B) = !A && !B:

<?php if(!Is_front_page() && !is_page('my-page-1') && !is_page('my-page-2')) : ?>

Upvotes: 2

Related Questions