I need to render something in the header of a wordpress theme as long as its NOT 2 pages. The logic I'm following, in plain english:
"If it's NOT this page, OR it's NOT this page then go ahead and render it."
Previously my code looked like this:
<?php if (!is_page( 'Page Title 1' )): ?>
<script>console.log("the message")</script>
<? endif; ?>
Which worked - when it was NOT "Page Title 1", it rendered.
Now, I want to do, if it's NOT "Page Title 1" OR "Page Title 2" then go ahead and render. In practice, I'm trying to achieve this by going like this:
<?php if (!is_page( 'Page Title 1' ) || !is_page( 'Page Title 2' )): ?>
<script>console.log("the message")</script>
<? endif; ?>
What ends up happening is it's backwards - it renders ONLY on those 2 pages but nowhere else? Why?
https://www.php.net/manual/en/language.operators.logical.php
$a || $b Or true if either $a or $b is true.
From that documentation I also tried:
<?php if (!is_page( 'Page Title 1' ) xor !is_page( 'Page Title 2' )): ?>
<script>console.log("the message")</script>
<? endif; ?>
$a xor $b Xor true if either $a or $b is true, but not both.
But this gives the same result, it ONLY renders the console.log on BOTH of those pages, when it should NOT render on both of those pages.
There's some sort of massive logical hole here, what am I doing wrong?
For what it's worth, I also tried:
<?php if ((!is_page( 'Page Title 1' )) xor (!is_page( 'Page Title 2' ))): ?>
<script>console.log("the message")</script>
<? endif; ?>
question from:https://stackoverflow.com/questions/65942732/render-if-its-not-one-page-or-another