• Resolved Brian

    (@bzabel)


    Hi. How do I remove a certain widget from more than one page? I have used the following code to remove from a single page:

    !is_page(page-name)

    I’d like to remove the widget from two pages on my site, but still have it remain on the others. Using the examples below, here are the pages I’d like to remove the widget from:

    page-name
    page2-name

    But I can’t figure out how to apply that logic to more than one page. I’ve tried every way I could think of and can’t get it to work. Would appreciate any help!

    • This topic was modified 6 years, 6 months ago by Brian.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Brian

    (@bzabel)

    Solved. I found the ‘&&’ logic to apply to multiple pages.

    max

    (@maximledoux)

    FYI you need to use it like this !is_page('page-name') not !is_page(page-name). If you don’t use the '‘s then it will generate a notice error about an undefined constant. It won’t break your page load, but it will use up server resources, and if you had a lot of traffic that would compound and slow down your site.

    If you’re using && like so: !is_page('page-one') && !is_page('page-two') that probably would not produce the desired result. All pages will meet the requirements because no page can equal is_page('page-one') && is_page('page-two'). I think you would want the OR clause (||). !is_page('page-one') || !is_page('page-two').

    However, it would be cleaner to use an array.

    You can use an array like so to exclude the two pages:

    !is_page(['page-one', 'page-two']) or !is_page(array('page-one', 'page-two')). ([] = array(), if you didn’t know. Fewer characters is always better because it takes less time to process.)

    Thread Starter Brian

    (@bzabel)

    Thanks, Max. I think it was working the way I had it, but took your advice and applied the array. Like you said, less characters is better, so why not. Seems to working just fine. Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Remove widget from certain paige’ is closed to new replies.