X

How to Disable Widgets on Specific Pages by User Level

Snippets by IsItWP

Are you looking for a way to disable widgets on specific pages by user level? While there’s probably a plugin for this, we have created a quick code snippet that you can use to disable widgets on specific pages by user level in WordPress.

This code will disable widgets on the homepage only without completely disabling widgets. You could change is_home() to is_page() or specific pages.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:


add_filter( 'sidebars_widgets', 'disable_all_widgets' );

function disable_all_widgets( $sidebars_widgets ) {
if ( !current_user_can( 'level_5' ) ){
     if(is_page('about-us')){
        $sidebars_widgets = array( false );
	return $sidebars_widgets;
        }
   }
}

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 12 best WordPress plugins for bloggers and how to secure your WordPress forms.

Comments  Leave a Reply

  1. Hi, i want to disable a inbuilt category widget. I am using clipper theme, and i dont want the category widget to get displayed on the category page. What would be the code and where do i need to put the code?

  2. Any way to target specific widgets, say turn of all text widgets on page ID x?

    1. hi andy, please I want to target a specific widget on a page with a template… what im tryin to achieve is replicate a widget area under an existing widget such that i can attach a new menu to the new widget area; and then remove the one above it which is curently existing …

  3. This is great when using WP as a CMS, great little snippet love this 🙂

  4. Tweets that mention Wordpress Disable widgets on specific pages – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com November 22, 2010 at 10:01 am

    […] This post was mentioned on Twitter by Hash WordPress, Patricia Skinner. Patricia Skinner said: RT @hashwordpress: RT @wpsnipp #wordpress Disable widgets on specific pages http://bit.ly/cPS1eV #blog please RT 🙂 […]

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!