Running EE 3.5.15

I am trying to show content based on URL segment and the following is not working correctly:

 {if "{segment_2}" != "portfolio" || "{segment_2}" != "photos"}
  <p>Conditional content.</p>

If I use one of the conditionals by itself it works correctly, but when I introduce the OR into it, it fails.

I have tried the following:

{if "{segment_2}" != "portfolio" OR "{segment_2}" != "photos"}


{if segment_2 != "portfolio" || segment_2 != "photos"}

I have also tried it with single quotes.

Any suggestions on this elementary issue will be appreciated.


Well here is the issue. You are trying to give OR condition for 2 strings. OR condition will return true if any one of the given statements are true.

If you want to execute the code when url_title not equal to "portfolio" neither equal to "photos" use this condition:

{if segment_2 != "portfolio" && segment_2 != "photos"}
    <p>Conditional content.</p>

Or as a simle way:

{if ! "portfolio|photos" *= segment_2}
    I am here
  • 1
    Thanks Mufi. While the logic at first does not make sense because technically you can't be on both pages at once, it does work and who am I to argue with success? – forrest Feb 16 '18 at 14:17

You should try your code in below manner.

{if ! 'portfolio|photos' *= segment_2}
    <h1>Conditional content.</h1>

You can also try in another way also.

{if segment_2 == 'portfolio' OR segment_2 == 'photos'}
    <h1>Conditional content.</h1>
  • Harsh, thank you for the suggested solutions. The first one did not work, although I wish it had because it is tidy. The second option did work. – forrest Feb 16 '18 at 14:15


 {if segment_2 != 'portfolio' OR segment_2 != 'photos'}
        <h1>Conditional content.</h1>

I've just tested, it works fine.

  • I tried it and it will not work for me. Thank you though. – forrest Feb 16 '18 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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