Home / functions.php / Disable widgets on specific pages by user level
  • How to Disable widgets on specific pages by user level

    no thumbnail sorry: Disable widgets on specific pages by user level

    Adding this php code to your functions.php will disable widgets on the home page only, without completely disabling widgets. You could change is_home() to is_page() or specific pages.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    <?php
    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;
            }
       }
    }
    ?>
    

    ( WordPress codex functions, hooks, in this snippet. )

    sidebars_widgets, is_page, current_user_can, user_can, add_filter,
  • Pingback: Tweets that mention Wordpress Disable widgets on specific pages – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com()

  • This is great when using WP as a CMS, great little snippet love this :)

  • Andy Woznica

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

    • samuelson

      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 …

  • Aniket

    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?