How to Customize or Disable Sidebar Widgets on Specific Post/Page in WordPress?

Last updated
App Shah

Crunchify » WordPress Optimization and Tutorials » How to Customize or Disable Sidebar Widgets on Specific Post/Page in WordPress?

WordPress Sidebar Widgets

In WordPress ecosystem, Widgets are essentials.

  • Widget Options Delivers Powerful Features in Lightweight Plugin.
  • The Complete Guide to WordPress Widgets.
  • Widget Options – World’s Best WordPress Widget Control Plugin.

We usually use average ~10 widgets at any given time. There are few in Sidebar and few in Post contents. By default WordPress doesn’t provide any simple utility by which you could disable specific widget on specific post/page, etc.

Option-1 – Manually

As often you need to disable Sidebar Widget on Specific Post/Page, below simple code snippet will help you to perform the same.

Just add below to functions.php file and you are all set.

add_filter( 'sidebars_widgets', 'crunchify_code_disable_widgets' );
function crunchify_code_disable_widgets( $sidebars_widgets ) {
        if (is_single(array(5,123,43,54))) // replace this with post/page ID
                $sidebars_widgets = array( false );
                return $sidebars_widgets;
}

Option-2 Using Plugin

Widget Options is a WordPress plugin which provides nice functionality using it you could hide or show widgets based on Category, Post or Page.

Display Widget WordPress Plugin Options

With Widget Options WordPress Plugin, you can easily assign pages visibility and restrict each widgets on different pages, posts, custom post types, categories, tags.

Widget Options Plugin

Let me know if you have any questions and I’m more than happy to provide an update quickly.


How to Disable Block-Based Widget Editor?

Genesis Framework by default disables block-based widget editor. If you don’t see that disabled then add below code to disable it.

add_filter( 'use_widgets_block_editor', '__return_false' );

To enable it back forcefully then use below code.

add_filter( 'use_widgets_block_editor', '__return_true' );

Let me know if you face any issue setting this up.

14 thoughts on “How to Customize or Disable Sidebar Widgets on Specific Post/Page in WordPress?”

  1. Hi. Perfect guide! Is it possible to use a similar code to disable the sidebar in a specific category?
    (All articles in this category will be without a sidebar)
    Thanks

    Reply
  2. I guess this code doesn’t work u.
    my WordPress 5.2.1.
    and i try edit page ıd and paste functions.php.
    sorry my english

    Reply
    • Hi Feilian – I’ve just tried and it’s working fine.

      What error are you getting? Could you also send me complete code which you put in functions.php file?

      Reply
  3. Hi there — Thanks for your help. I had one issue when I tried option 1. Although it disabled the sidebar, it also disabled my footer widgets only on that page. Do you have an updated code for this? I’m using twentyseventeen theme and the native footer widgets. Thanks a bunch!

    Reply
    • Hi Kenneth – I never worked with twentyseventeen theme. I’ll give it a try later this month. Meanwhile let me us know if you found a solution for the same.

      Reply
  4. Work really well for me but i have one question: how can specify a specific widget in a specific page?
    The way you show up disable all widgets but i really want more control. Thanks for your post anyway!

    Reply
    • Hi there – I would suggest you to use Display Widget as it provides more granular control over manual steps. Let me know if you have some more requirements than what it provides. I would love to work with you on your scenario.

      Reply
      • Hi, App Shah. I did not screen-dump the error, unfortunately, but I had to take the code out of functions.php via FTP, before I could access the site again, from both front- or back. It was in line 30, I remember, which I’m pretty sure was this line

        $sidebars_widgets = array( false );

        but if I put a space in-between the new code and the old, it would have been this

        if (is_single(array(9341))) // replace this with post/page ID

        I decline to retry the attempt now. I have changed template away from twentysixteen to one with the abiliy to disable sidebar built-in.

        Thank you for replying so fast, but as I am in the midst of moving the WP page in mention to its own domain, I cannot afford mistakes.

        Reply

Leave a Comment