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
[...] Disable widget areas (sidebars) without touching theme templates (tags: wordpress howto widget widgets arb) [...]
[...] Disable widget areas (sidebars) without touching theme templates [...]
[...] Disable widget areas (sidebars) without touching theme templates [...]
[...] Disable widget areas (sidebars) without touching theme templates [...]
[...] Disable widget areas (sidebars) without touching theme templates [...]
[...] VAI AL SITO » Condividi e Diffondi: [...]
[...] Disable widget areas (sidebars) without touching theme templates Hello Friends! We Regularly post Tutorials, Freebies, Inspirations and other Useful Design Resources.If you are new here, Make sure to Subscribe to our RSS Feed for more Updates. It’s FREE [...]
Wonder how I can disable just one widget on a certain page..
[...] Disable widget areas (sidebars) without touching theme templates [...]
This is a great way to make certain parts of your theme look and function differently from the rest of the theme!
Regards
[...] Disable widget areas (sidebars) without touching theme templates [...]
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:
“if ( is_single() )”
to
“if ( is_page(#) )”
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.
[...] Disable widget areas (sidebars) without touching theme templates [...]
[...] Disable widget areas (sidebars) without touching theme templates [...]
[...] Disable widget areas (sidebars) without touching theme templates Добавить в социальные закладки [...]
@Coafuri,
Which is the plugin that you use?
[...] Source [...]