1

I'm not very good at this, so please bear with me. I have a Wordpress site with sections for different cites, and the different cities each have their own nav menu which shows for all of the pages in that city.

if ( is_page( 'phnom-penh' ) || in_array( '11760', $ancestors ) ) :
    get_sidebar( 'city-phnom-penh' );

However, I want to remove the menu/sidebar just from one page in the Phnom Penh section so I can add a widgetized sidebar to that page instead. Is it possible to have this sidebar apply to all pages in that section except for one?

2
  • Yes - it's possible - does your code not work, if not, what errors do you get? - perhaps try ! is_page( 'phnom-penh' )
    – Q Studio
    Commented Jan 29, 2021 at 12:22
  • Sorry, I don't understand what you mean. The code above puts the sidebar on all pages within the phnom-penh section, but I want to specifically exclude one page within that secion. How do I do that?
    – Lina
    Commented Jan 29, 2021 at 13:30

1 Answer 1

0

As I noted in my comment, you can use the negation operator, like so:

if ( ! is_page( 'phnom-penh' ) ) {
    get_sidebar( 'not-phnom-penh' );
} else {
    get_sidebar( 'phnom-penh' );
}

Note the ! before the is_page - that means NOT.

Also note that if you use more than once condition via || or OR and either of the conditions returns true - the sidebar will be returned.

2
  • So that means if the page is NOT phnom-penh it will get the all-other-cities sidebar? The issue is the specific page I want the alternate sidebar is nested under phnom-penh. Could I do something like this? if ( is_page( 'phnom-penh' ) || in_array( '11760', $ancestors ) ) : get_sidebar( 'city-phnom-penh' ); if ( is_page( '83571' ) get_sidebar( 'sidebar' );
    – Lina
    Commented Jan 29, 2021 at 14:34
  • Updated with an example..
    – Q Studio
    Commented Jan 29, 2021 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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