The smart way to disable your sidebar

If you find yourself making a new WordPress template for pages that are identical to others on your site but just don’t have a sidebar, consider this technique instead which lets you turn the sidebar off selectively on a page by page basis.

Add this to functions.php

index.php, page.php … etc.

Next find the file that has the sidebar in it. If you want this to work on all blog posts, it’s probably single.php, or if you add it to index.php and/or page.php it’ll work on other types of pages. Once you find your sidebar you need to put a bit of code before it and a bit of code after it. In the beginning bit looks to see if the custom field is set on your page, the second bit is just the end of the ‘if’ statement

what it does

It checks to see if you have a custom field set in your post to disable the sidebar and if you do it turns off the sidebar

how to use it

Just make a new custom field for your page called disableSidebar and set it to true. That’s it.

Topics covered:
  • Thanks!

    It worked well

  • Scott

    where do you put the code snippet?

    • It replaces get_sidebar(); in any of your templates

  • Thank you so much,really works !

  • Let me try this tweak and see what happens. Thanks.

  • Jeff

    Works great. Thanks!

  • kevin

    Thank you very much!

    Was looking for this code for a while!

  • Victor Ndiema

    Thanks for the code, but suppose I would like to remove only a single sidebar either left or right, how do I tweak the code.

    • That's pretty easy, you'd just change all the instances of disableSidebar to disableSidebarLeft or disableSidebarRight or disableSidebarWhatever, and then in the custom fields you make on the page/post you'd set disableSidebarRight to true to disable that one specifically. If the page doesn't have the specific custom field in listed in the code the sidebar will show up. Hope that helps.

  • irene

    Thnaks so much for great tip.

    One more help, if you don't mind.

    When I do this, i need the wide of main column also change to cover the empty space of sidebar are.

    Any possible way to do this? Thanks in advance.

    • If you float left (or right) your sidebar and give it a width but don't give a width to your content area (it defaults to width: auto;) then the content should take up the extra space when you remove the sidebar.

  • irene

    i'been change the width of content column to auto.

    Result; the width of content change to full (same as i wish for).

    However, for the posting that enabled sidebar area, the content also full width and the sidebar area move to down of the content.

    I have 3 column for my magazine theme.

    Main content in the left column, and 2 sidebars in the right column.

    Here is my style.css;

    — insanely long stylesheet removed here —


    I'm not so familiar with css, any help would be appreciate.

    Once again, thanks for your help.

    • Hey Irene, If your sidebar is wrapping below the content when you have the content area set to width: auto; there could be any number of things causing it… Maybe google 'three column css layout' and try some of the tutorials out there for making a good css based three col layout.

  • MiK

    Thank You! Using the same way i managed to disable the title 🙂

  • Which file exactly does this go on? page.php?

    • it can go into any template, page.php, index.php, a custom template… wherever you'd normally put a sidebar in your code…

  • I put the code in my the index and page.php files but when I create a field disablesidebar and set it to true nothing happens

    • did you replace the code that normally calls in your sidebar with our code? if you just add it in addition to your other code you'd probably get two sidebars… Are you sure you have the custom field exactly as the example? it's case sensitive…

    • it's disableSidebar not disablesidebar (case sensitive)

  • I am using the Web Minimalist Theme. I have tried pasting this code in multiple places and it does not seem to affect anything. It appears that all sidebar calls are in the stylesheet.

    Do you have any suggestions?

    I have added the custom field as indicated above.

    Thanks for any suggestions that you may have. I appreciate it.

    • You need to replace the code that is in your theme that calls your sidebar with this code. Sidebar calls aren't in the stylesheets they're in the php template files.

      • Hi,

        That is my problem. This theme does not have a template.php. The page.php does not call the sidebar.

        The only files where I see sidebar mentioned are the Stylesheet and functions.php, which has this code: <?php

        if ( function_exists('register_sidebar') )


        OH there is also a sidebar.php

        I am going crazy trying to figure this out. I think that the theme (Web minimalist) is strange or I am just very stupid. Any further suggestions greatly appreciated. Thanks.

  • katie

    The idea here is that you will modify your page.php file to check for a “disable sidebar” indicator (aka a custom field) for each page. Then, anytime you want to create a page with no sidebar, you simply set a custom field to indicate that you wish to disable the sidebar for that specific page.

  • James

    Hi, I need help please.

    The theme I am using allows you to choose whether you want one sidebar or two, and also which side of the page you want the sidebar.

    This is the current call code

    When I replace it with this

    ID, 'disableSidebar', $single = true);

    if ($disableSidebar !== 'true')

    $loc = theme_option('sidebar_location');

    if($loc==2 || $loc==4) {

    get_sidebar(); // calling the First Sidebar


    if(theme_option('sidebar_width2')!=0 && $loc!=3) get_sidebar( "second" ); // calling the Second Sidebar


    I remove the sidebar from the page that I want it removed, but on the pages where I want it to remain the sidebar stays on the left side of the page even when I select for it to be on the right.

    Can someone please help me with this.

    Thank you


  • James

    Hi, I need help please.

    The theme I am using allows you to choose whether you want one sidebar or two, and also which side of the page you want the sidebar.

    This is the current call code


    When I replace it with this

    <code>ID, 'disableSidebar', $single = true);

    if ($disableSidebar !== 'true')

    $loc = theme_option('sidebar_location');

    if($loc==2 || $loc==4) {

    get_sidebar(); // calling the First Sidebar


    if(theme_option('sidebar_width2')!=0 && $loc!=3) get_sidebar( "second" ); // calling the Second Sidebar


    I remove the sidebar from the page that I want it removed, but on the pages where I want it to remain the sidebar stays on the left side of the page even when I select for it to be on the right.

    Can someone please help me with this.

    Thank you


    • I don't see this anywhere in your code:

      <code>$disableSidebar = get_post_meta($post->ID, 'disableSidebar', $single = true);</code>

      That's the part that looks for a custom field and turns off the sidebar, I'm guessing thats further up in your code?

      Other than that I don't think I can help, there's too much going on in your theme for me to know what's wrong. Normally if you have multiple sidebars you'd wrap each with a different conditional statement using different variable names like $disableSidebarLeft and $disableSidebarRight.

      Good luck

  • Please,I am soo novice that i need help with how to make a new custom field for your page called disableSidebar and set it to true to start with.


    • one of the boxes when you are making a new post or page is for adding custom fields, if you don't see it that means you probably have it turned off in the screen options. Click the little button on the top right of your screen that says 'screen options' and make sure it's checked, that's probably the problem.

  • rob nelson

    I love the idea of this condition = true stopping the side bar from coming up. I have pasted the code in index and page ,php. And set my condition correctly but the side bar is still there.

    I am using the Chip Zero Theme.

    Thanks for any help you can provide.

    • there's not anything in the code that would conflict with a certain theme, the only thing I can think of is that your theme is registering and calling a specific sidebar and not just 'sidebar' so whatever code you had in your theme for calling the sidebar would need to be used, so in the code below, where it says get_sidebar(); that might need to be something more specific, like get_sidebar('name-of-sidebar'); you'd see this name in the call to the sidebar, that you are replacing, also if you replaced it already you could look at functions.php to see what sidebars are registered…

      <?php // look to see if we've disabled sidebar in a custom field, if not show it
      $disableSidebar = get_post_meta($post->ID, 'disableSidebar', $single = true);
      if ($disableSidebar !== 'true') { get_sidebar(); }

  • Hi I'm trying to remove the sidebars from my search page. I'm using Genesis, when i go into wp-admin->appearance->editor, I looked into all the php files, but there isn't a "get_sidebar" entry.

    Would appreciate any help. Thanks.

    • could be that it's using the dynamic_sidebar(); function, if so follow the same steps above but just replace get_sidebar with dynamic_sidebar. Let me know if that works for you.

      • Hi, Your code is working on my site. I have few other things to ask. The excerpt what I write is not spreading but stays where it was. I would like to set it to fluid so that whenever I do not have a sidebar then the excerpt should take the place of the sidebar and spread wide. I am doing this on a photography post. Where I would put big photos. So please let me know if I can do this anyway.



        • Hey Hahid,

          This has to do with the CSS in your layout. For instance if the content area has a px width instead of being set to auto this would happen… You'd need to make a few changes to the CSS. What's the link to your site where I can see the problem?

        • My site is

          This piece of code works for the single.php i.e single post.

          #content { float:left; background:#fff; width:640px; margin:20px 0px 0px 0px; padding:0px 0px 15px 0px; }

          U can see the width set to 640px.. Now tell me how do I set it to float over sidebar area when there is not sidebar and narrow down to regular width when there is sidebar.

          i am sorry if this comment is repeated…

          • it's an easy fix actually, just change the width: 640px; to width: auto;

            I just tested it in firebug and looks like it works.

  • wow that was quick. Thank you for the advice. How much do you charge for a wordpress design? Please give me your rates, I get wordpress projects.



    • depends on the site, you can always contact us via the contact page if you have a project, would love to hear from you.

  • James

    Really helpful, I have no experience with wordpress and this has now made my theme worth keeping. Very thankful!

  • I have a very basic theme with no custom fields. I installed "More Fields" to have custom fields, but I'm not sure how to use them.

    I want to remove the sidebar from my homepage only (static page on WordPress) and I do NOT have the <?php get_sidebar()> code in ANY of my theme files. Hence, why I am having such a problem.

    I love how easy this code looks, but I do not know where to put the code to make it work. is the site.

    Any help is greatly appreciated!


    • you must have get_sidebar somewhere or you wouldn't have a sidebar on the page. Is it all that stuff on the bottom of your home page you're talking about? that does look like a sidebar of sorts, maybe your home page uses a custom template like home.php

  • Lalit

    On Which file do I need to insert or add above code?

    Lalit from Tricky Planet

    • depends on your template, but most likely index.php or page.php, or a custom content type template…

  • esty

    hello, I want to remove a side bar on one of my wordpress pages and only on one one page and I am afraid to put the remove sidebar code because I do not want to put it in the wrong place and remove all the side bars. where should I go and what should I put in to remove only on that specific page

    • b

      That’s what this code does, you put it around your sidebar call, then on just the pages you want the sidebar removed you set the custom field.

      • Victor

        my god! what’s a custom field?
        What’s it look like?
        Where to put it?
        How to create it on WordPress?
        Is it a plugin?
        Does it placed on the editing page of wp-admin?

        • no plugin necessary Victor, custom fields are just part of WordPress, if you don’t see them on your page or post you can click the ‘screen options’ button at the top of your screen and turn them on.

  • jlhstudios


    Thanks for creating and providing this code.
    Below and between the two dashed lines… is what my page.php looks like in my theme.
    Where do I add your code?
    I numbered the rows so we can communicate much easier.
    Can you tell me what line to remove?
    Can you tell me between which two lines to add your code?
    I copied your code and pasted it here…is the code I copied correct?

    ID, ‘disableSidebar’, $single = true);
    if ($disableSidebar !== ‘true’) { get_sidebar(); }

    8. <div id="page-” >


    Thanks for all of your kind help.

    • jlhstudios

      I copied the code again below because it looks like an error occurred and it didn’t post correctly.

      <div id="page-” >

      • Brent Lagerman

        I don’t think the code is coming through can you instead use and send me a link to it so I can help out. Sorry for the delay on this, been kind of slammed with work lately. But basically you put the code around your sidebar php call, so you need to find get_sidebar(); in your template then put the code around that. That will make it so that you can disable any sidebars on a page-by-page basis with a custom field. If you just want to remove the sidebar all together on all pages, then just delete get_sidebar(); from your template. Hope this helps!

      • if you are having problems showing me code it’s probably better to just use and send a link in a comment instead

    • I see a few problems. First off you don’t have a sidebar here to disable, maybe some code is missing? The sidebars usually come in using get_sidebar(); Also the code you copied isn’t complete, it starts with the –recheck above.

  • Awesome share =) This works perfectly, but to truly get the webpage to adjust to the extra space saved (after removal of the sidebar on the page)

    If you are using Twitter Bootstrap 3.0, you simply setup an IF / Else statement to accommodate the width. I had to manually adjust this even more since the width is adjusted by the management settings for the wp functions. I will add my code below for those to see. I hope this helps.

    Some Helpful Resources I had to review and catch up on:
    I had to use Alternative PHP also:
    PHP Parser that is handy:
    WP Codex Pages:

    Attached below are two images of the code I used for my index.php.

    • Oops. The last line i wrote above the attached images is wrong.
      “Attached below are two images of the code I used for my index.php.”

      It should be:
      Attached below are two images of the code I used for my page.php.

  • Will Hamilton

    Is this still a possibility? I’ve tried to do this with my site, but when I add the code to my single post it seems to break the footer as well as removing the sidebar as it’s considered a bottom sidebar by the theme. The theme I am using is Nirvana on

    • this would work on any sidebar, footer sidebars included. Just make sure you wrap it around only the sidebar, the sidebar needs to be self contained – make sure you don’t have an end div tag in there for instance from another area… If you want to send me a pastebin or codepen with the code I’d be happy to take a look

      • Will Hamilton

        i have literally no idea how to do that, i have very limited knowledge of php code.

        • ah ok gotcha. I edited the post a bit to make it more beginner friendly, can you try following the instructions again? You will need to edit the PHP files using your text editor or WordPress’ editor

  • dreweastmead

    I did the first step, added 5 lines of code to ‘functions.php’ and my entire wordpress site and admin side went blank. now i have no way of even logging into my admin site to undo what i just did. awesome. thanks a lot!

    • MysticalSilence

      Go to your cPanel on host and navigate to functions.php of your theme. Then open the file in an editor and delete all changes. It worked for me.

  • Musharib Yousafzai

    this is so bad when i paste the code in my functions.php file my entire site work stoped, as well as my wordpress admin page not showing please guide men what should i do for recover my site???

    • Elkanah Nyauma Ondieki

      Log in to your cpanel, click on file manager and go to public.html folder. Click on wp-content (if you are using WordPress to design the site) and locate themes. Delete the theme and reinstall it again, your website will be back to normal again.

      • David Pardo

        how do i reinstall it??! where do i get it from?

        • Elkanah Nyauma Ondieki

          Sorry David for not responding to your question. I do not know whether you still need an answer or not but the answer is this. If you have the theme in your computer, login to your cpanel, click on file manager and locate the folder public_html (which has all the files you need for the website. If you are using WordPress as your web design platform, click on wp-content, go to themes and you will see the theme that you need to uninstall. Delete it and install it afresh and your website will be back to normal only that you will need to make some few edits….thanks. Let me know anything else regarding WordPress, I will be happy to help.

  • Rishitha


    I want to remove sidebar from all pages. I went through the above code and I am not very clear about where to paste the above code in order to disable the sidebar. My single.php looks like this. Could you please help me with this? Also I had experiences of the whole site stopping working as soon as I modify something in functions.php file. Can anyone please share what precautions we need to take before deploying changes to our functions.php page.

  • David

    i messed something up…real bad. i posted the code to the function.php page but it gave me an error in line 424 (something like that). i removed the code and refreshed and now the page wont load.

    please help!

    • David Pardo

      Parse error: syntax error, unexpected ‘<', expecting end of file in /home1/davidpc7/public_html/wp-content/themes/twentysixteen/functions.php on line 424

Enable Javascript