1

I've been using this if conditional statement to only show content if the current page is NOT using a certain page template;

if (! is_page_template('template-custom.php')) {
    <!-- show some content  -->
}

which has been working fine. Only now I need to amend the statement to show content if the current page is NOT using one of 2 templates (So if the current page uses template-custom.php or template-custom2.php do NOT show the content).

I tried this;

if (! is_page_template('template-custom.php') || is_page_template('template-custom2.php')) {
    <!-- show some content  -->
}

and this;

if (! is_page_template('template-custom.php') || ! is_page_template('template-custom2.php')) {
    <!-- show some content  -->
}

but to no avil.

Any suggestions?

1
  • This is pure PHP as per answer, you need && (and) not || (or).
    – Rarst
    Commented Sep 23, 2013 at 10:20

3 Answers 3

3

If you want don't want to show content if the current template is template-custom.php or template-custom2.php you can use:

if (!is_page_template('template-custom.php') && !is_page_template('template-custom2.php')) {
    <!-- show some content when you AREN NOT in template-custom.php NOR template-custom2.php -->
}

or

if (is_page_template('template-custom.php') || is_page_template('template-custom2.php')) {
    <!-- show some content when you ARE in template-custom.php OR template-custom2.php -->
}
0
0

According to De Morgan's law

"not (A or B)" is the same as "(not A) and (not B)"
-2

try this:

if (! is_page_template('template-custom.php') || ! is_page_template('template-custom2.php')) {
    <!-- show some content  -->
}
1
  • Tried that. Nothing Commented Sep 23, 2013 at 10:18

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