One thing that’s always bothered me about needing to remove widget areas in WordPress is that you have to dive into template files to do it. For example, I may want to create a post that doesn’t need widgets shown. That typically requires a little editing of my files.
If you know me well enough, then you know that I hate for anyone to edit templates in a WordPress theme, even if that person is me.
So, what I’ll be showing you is two quick and easy ways to disable widget areas using your theme’s functions.php file. Technically, what we’ll be doing is disabling the widgets, which is basically the same thing when you get right down to it.
This article assumes that your theme sets no default code if no widgets are shown. Otherwise, it is outside the scope of this tutorial.
Removing all widget areas
What we’ll be doing in this first function is disabling all widgets on the home page. First, open your theme’s functions.php file and input this PHP code:
<?php
add_filter( 'sidebars_widgets', 'disable_all_widgets' );
function disable_all_widgets( $sidebars_widgets ) {
if ( is_home() )
$sidebars_widgets = array( false );
return $sidebars_widgets;
}
?>
This is a function that will remove widget areas from our home page. Well, you might have other pages, posts, archives, or whatever in mind that you want to disable widget areas on. In that case, you need to look up the appropriate WordPress conditional tag.
Removing a single widget area
Let’s suppose your theme has widgets in multiple places. Let’s further suppose that you want to remove only the footer widget area on single posts. This will be basically the same thing as above, but you need to know the ID of the widget area. This will be something you’ll either have to find in your theme’s code or ask your theme author about.
For the sake of this tutorial, the ID of our footer widget area is simply footer. We’ll create a new function for this as well. Add this to your theme’s functions.php file.
<?php
add_filter( 'sidebars_widgets', 'disable_footer_widgets' );
function disable_footer_widgets( $sidebars_widgets ) {
if ( is_single() )
$sidebars_widgets['footer'] = false;
return $sidebars_widgets;
}
?>
Again, we used a WordPress conditional tag to check if it was a single post.
Why use these methods as opposed to directly editing templates?
One of the biggest issues between theme authors and users happens when it’s time to upgrade a theme. Users don’t generally know the best way to accomplish something like removing a widget area without compromising the original code. Therefore, the user might not upgrade his or her theme and take advantage of the benefits of better code.
WordPress allows a functions.php file in themes that’s ideal for overwriting things. The more we keep users out of theme files, the easier it becomes to upgrade themes for both theme authors and end users.
Also, theme authors should take a good look at the above functions. This is a great way to make certain parts of your theme look and function differently from the rest of the theme. Use your imagination (Ex: pages without sidebars, custom fields to remove widgets, etc.).

Simple, but great!
To be honest, I’d hack the theme files and create a mess. I’m really going to try to use functions.php more often now (and move some of my custom plugins into there as well). Thanks for showing the way…
Stephen Cronin — Another great thing about using
functions.phpis that changes are more easily carried from theme to theme. The less hacking you do when switching themes, the better. Plus, you always know where your custom stuff is at if you need to tweak anything.Good work, Justin. For some weeks, I had been looking for an easy and understandable explanation of this technique (my skills in PHP are very limited) in order to apply it to my blog. I’ve just published an article with a demonstration: Desactivar la barra lateral sin tocar las plantillas de WordPress. Thank you very much.
http://www.livexp.net/wordpress/remove-widget-areas-without-editing-wordpress-template.html
Dear Justin
Today I come across the article ( link above) that is exactly like yours in this post.
So, this is just to let you know.
I have been reading your blog for awhile and using your wptheme (hybrid) and
It’s the greatest wptheme around. I admire the way you write code.
I hope you keep up the good work and be more success in the future.
Paul
Wonder how I can disable just one widget on a certain page..
So I tried changing the “['footer']” part of the code to the name of the widget area I need to remove, and nothing happened. I have a suspicion that I need to change more than that in the code. Do I also need to change the “disable_footer_widgets” lines? I’m not sure what to put if that’s the case. I have tried changing it to just “disable_footer_widgets”.
The title of the widget area I’m trying to remove is “Secondary Sidebar #1″. Any thoughts? I appreciate it!
Oh, and to The Frosty. I would assume if you want this to work on a specific page, you would change the code:
with “#” being the numerical ID of the page. Although again, this hasn’t worked for me, because the code hasn’t worked on single posts or pages with any method I’ve tried so far. But maybe you’ll be luckier!
Oau..it’s quite simple. Until now i use a special plugin o do that.
@Coafuri,
Which is the plugin that you use?
This is a really useful tip.
Let’s suppose that our WP3 site doesn’t support widgets at all: they aren’t necessary.
How can we remove from the admin menu area, under “Appearance”, the menu “Widgets” also?
Thank you!
Hey, why not use the widget logic plugin?
Because you can’t disable sidebars with the Widget Logic plugin.
Hey Justin, nice trick, by the way, i’m playing with this code i made:
There you can see i’m able to get all active and inactive widgets, not the widgets areas, each widget id.
So, then i can run a single
wp_unregister_sidebar_widget([some_id]);to disable any widget from any page or post.But, i can’t figure how to do the reverse thing, i mean to register dinamicly one of the inactive ones in a certain widget area.
Got what i mean?
Well, that’s it, you have my email, pleas reply if you found how to. Thanks.
I can’t get this to work targeting a single widget… Maybe I’m misreading the post though.
I can remove a single “widget area”, ie. an entire sidebar, but can’t seem to target individual widgets within a widget area.
This works:
This doesn’t:
This looks like it is exactly what I need. Thank you
I could use some help though /*noob alert*/
Where is the proper place to paste the code that Justin provided at the beginning of this post. I know it’s in the functions.php file, but where specifically should it be posted. I see other filters in the file, but every time I paste it, I get an error…
Thanks for your help!
Very good blog! Do you have any hints for aspiring writers? I’m planning to start my own site soon but I’m a little lost on everything. Would you suggest starting with a free platform like Wordpress or go for a paid option? There are so many choices out there that I’m totally overwhelmed .. Any suggestions? Appreciate it!
Is it possible to disable all widgets on a per page basis? If so, how? Thanks!
Even better would be to do this in a child theme with its own functions.php file that way you really aren’t editing the theme files at all. Of course you have to stop a tutorial somewhere…
Remove this code from index.php
get_sidebar();