Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
104 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...