Thanks to Milo and G.M. for pointing to the master key, as G.M. said:
you have to use a lower priority than one register_sidebar runs, but
lower priority means higher number.
So the final code that is working:
function site_unregister_sidebar() {
if ( is_admin() && current_user_can('editor') ) {
unregister_sidebar( 'my_custom_widget_area' );
}
}
add_action('widgets_init', 'site_unregister_sidebar', 20);
Because I set my sidebar with priority of 10 with the same hook – widgets_init
.
function theme_widgets_init() {
register_sidebar( array (
'name' => 'Custom Widget Area',
'id' => 'my_custom_widget_area'
) );
}
add_action( 'widgets_init', 'theme_widgets_init', 10 );
Related Posts:
- Get list of all registered sidebars
- dynamic_sidebar not rendering sidebar
- Get custom side bar on custom post archive page
- Custom sidebar not showing in the dashboard
- Sidebar Generator? :)
- How can you add a link to a sidebar description?
- Creating a different side bar for single posts than for main page.
- Adding Multiple Sidebars
- How to increase maximum number of sidebars support?
- How to enable the default sidebar area?
- Sidebar widget not displaying after simple code update.
- Dynamic sidebar rendered in another place than i would like
- Dynamic Sidebar Conditional [duplicate]
- finding sidebar content in wordpress
- Sidebar only shows up on blog page
- How to troubleshoot Sidebar not being generated
- Why is my custom sidebar always open on the widgets screen in Admin?
- Custom sidebars – get_sidebar() problems
- Content not showing up when using custom template + sidebar
- How to make sidebar float right and site content left
- Call Multiple Sidebars at once
- Why isn’t my registered sidebar showing up in the admin?
- How to wrap the widget content with a div or get the widget title outside?
- Get sidebar parameters (before_widget, before_title, etc.) from within a widget
- Add div class to only one widget
- Registering Sidebars and Sidebar Widgets. Sidebar Widgets Not Displaying
- Add featured image to sidebar [closed]
- How the WordPress sidebar works
- How to exclude parent category but show child categories?
- Specific and Different Ads for each Post?
- Twenty Ten child theme has post on an inner page. Cant get that page to use my desired template
- Template part vs Sidebar (differences)
- Change sidebar headers from H1?
- Registering multiple sidebars with data from an array
- Best practices: Custom theme sidebar menu – hardcode or widget?
- WordPress widget new instance creates content duplicates
- How to delete wordpress menu
- CSS Twentyeleven / Sidebar has to be changed IN the CSS Stylesheet. Sidebar on the left side
- adding multiple sidebars on pages
- Why does the TwentyTen Theme sidebar have a class called ‘xoxo’?
- How to add Sidebar and Full width option in post editor
- how to exclude posts on current page from recent posts sidebar widget
- How to add a class when there’s no sidebar?
- Custom page sidebar using Template dropdown box
- Register/Get sidebar?
- How to have dynamic sidebar content per post
- From what hook on is it possible to conditionally add actions?
- Post thumbnails in sidebar & footer?
- Sidebar on the wrong side of the page
- sidebar parameters (before_widget, before_title) not Working
- 2 dynamic sidebars registered, not showing up
- Custom Sidebar only on single post
- Add #sidebar-2 to a custom page template
- Sidebar not appearing in footer, but it appears everywhere else!
- Where is dynamic_sidebar content defined?
- Common side bar for multiple websites
- Cannot retrieve author in sidebar of single.php
- get_sidebar() will not work in footer.php
- Gutenberg get wp registered sidebars
- How do I show breadcrumbs when sidebar is not applied?
- Adding an extra sidebar to your theme
- Why the dynamic_sidebar() call is putted into an ul tag?
- Find sidebar.php in WP 3.9.2
- Is there a way to dump all registered sidebar/widget?
- Sidebar not appearing on page template with custom posts
- get_posts() in secondary sidebar messes up content in primary sidebar
- Get specific sidebars $wp_registered_sidebars [closed]
- How to use full length of the upper part of the content and below of it is a content with a sidebar?
- WordPress – Allow dynamic text to be added into a sidebar upon page creation
- Sidebars are no longer working
- Why is registering a sidebar for each page causing my sidebars to reset?
- is_user_logged_in function in a sidebar not working
- Get or set values in post meta
- The WP home page corrupted after switching to new theme
- How do I fully rid of the 1px wide sidebar border? [closed]
- how do i get my sidebar above content on nanomag theme
- How to create sidebar from “scratch”?
- Change Sidebar for rewritten page
- How to get sidebar widgets in leftsidebar template
- Change page layout
- Need help with theme Business (Modern Themes): sidebar issue
- Undefined index: custom_sidebars
- How do I add a class to all sidebars to let a Google Custom Search Engine know not to index the content?
- I’d like to add an fa icon before a link in my ‘recent post’ side bar [closed]
- Echo there are no posts wp_get_archives
- How to change templates based on URL
- wp_register_sidebar_widget in loop within a plugin?
- is_home() and is_front_page() not working in sidebar
- Sidebar not visible after changing to new domain
- Resizing Picture
- Sidebar not displaying on custom-page.php
- Add the title of a widget as an ID – for anchor links
- Searchresult sidebar change
- How to hide a Sidebar from other admins?
- Differentiate Between Parent & Child Categories
- How to change font in title of sidebar widget [closed]
- Persistent sidebar.php [closed]
- Sidebar not appearing
- Woo commerce Single Product Sidebar [closed]
- sidebar choice not saved for pages (but saved ok for posts/custom posts) [closed]