You should do it with after_setup_theme
action:
function remove_inactive_widgets() {
$sidebars_widgets = get_option( 'sidebars_widgets' );
$sidebars_widgets['wp_inactive_widgets'] = array();
update_option( 'sidebars_widgets', $sidebars_widgets );
}
add_action( 'after_setup_theme', 'remove_inactive_widgets' );
Related Posts:
- Grabbing how Many Posts by Month for a Dashboard Widget
- Handling dozens of sidebars
- Widget Areas Still Appearing in WP ADMIN When They Shouldn’t
- Give Editor Access To Sidebar
- changing wp-admin/widgets.php
- Enabling jquery when dragging available widget to sidebar area
- Prevent widgets removal
- WordPress 4.8: Using multiple WYSIWYG-Editors with media inside of Widgets how to?
- How to Remove All Widgets from Dashboard?
- How do I save data from submitted form from widget
- How to listen to color changes on the color picker?
- Role that can edit only widgets, not other theme options
- Reorder dashboard widgets
- Ban certain widgets from certain sidebars
- Using tabs in admin widgets [closed]
- Completely disabling widgets
- Elegantly using JavaScript on widget admin forms
- Multiple users editting widgets
- dynamic_sidebar() returns false in admin section
- add_page_menu to make shortcut to widgets
- Widgets not expanding on wordpress 3.3 widget dashbord
- Remove/Add widgets from/to the Available Widgets pool
- jQuery UI inside widget on admin page
- How to get “Widget Logic” plugin’s input value in a custom widget code (to display on the Widget admin page)
- Add field to dashboard to update embedded URL on homepage?
- Dashboard Widgets – Add Admin Page With Same Functionality
- Drafts widget for admin page
- Validating widget’s configuration data on Admin page
- How to change color of registered widget areas in admin?
- Custom widget is not appearing in the admin area
- How to remove Help tab and the Dashboard widget area’s empty border
- Widget page stopped loading
- Adding a single text input field to a custom Dashboard widget
- How to change widget’s form color in admin?
- Issue with checked() echoing on to page
- Editing Help Section
- Allow users to give a dashboard widget a custom name using ACF
- How to customize WordPress dashboard for different users?
- Custom Admin Section
- Reposition the widget sidebar in Appearance->Widgets
- Widget stuck at particular point when dragging to bottom
- Creating an custom admin page for editing widgets
- jQuery “on” handler does not fire on newly inserted widgets [closed]
- Database size Widget
- Unable to add options on dashboard widget ?
- How to add the “page” post type to Recent Activity widget displayed in admin?
- Unique widget id in sidebar
- Taxonomies not showing in WP Dashboard Right Now widget
- trying to Change to wp_register_sidebar_widget
- Widget options – where to put them?
- Widget which displays thumbnails, but links to urls?
- twenty eleven single.php
- menu in different page in different style
- I add some js files from a plugin to a specific location
- Include widget within newsletter template?
- modify buddpress adminbar only in admin pages
- Correct way to add a block element to sidebar layout
- Add text to Text Widget using Javascript
- Admin Login page not working at all
- Custom widgets do not appear in dashboard > appearance > widgets
- How do I get shortcode, widget and template tag CSS to load in the head only as required? [duplicate]
- Widget on home page displays wrong time compared to same widget on inside pages
- Show parent-child relationship for categories in the wordpress admin
- Hide widget on page
- How to exclude a widget from showing up on a page?
- My understrap-child theme doesent have a head.php, footer.php
- How do you submit a widget for the wordpress directory?
- How to hide sidebar widgets in all pages except Hompage?
- How to delete Jetpack Widgets from the Widgets page in admin panel [closed]
- Using Conditional Tags to restrict something to 1 user?
- Widget logic not working
- Jetpack ‘Blog Subscription’ widget doesn’t add emails to
- How to customize dynamic_sidebar rendering? [closed]
- How to completely remove the sidebar? [closed]
- Subpages menu on sidebar plus widgets
- How can I add multiple content-editable blocks without a plug-in?
- How to find the exact widget details
- Widgets are not showing after moving domain
- Widgets in PHP files?
- Recent posts with different class name for each post and a scrollbar?
- Can’t use is_home in template-functions.php
- Putting a URL, for a preview, in a side bar
- How can I order the “Woocommerce Products Widget” by the sales date? [closed]
- You do not have permission to access this document on form submit
- Full Width Container Colour Problems
- Change the datasource of widget in a WordPress theme
- How to make custom dashboard widget to display alert in front-end?
- Widget does not work with WooCommerce enabled
- how to enable full width page template in woo theme memorable?
- Can’t remove a widget from admin
- Add a twitter feed to my WordPress website
- Using AJAX in a Widget to Sort items [closed]
- Problem on register/login widgets
- Extending Widgets – Exclude # of posts field from Recent Posts Widget
- How to show WordPress Dashboard Widgets on Frontend?
- Post Format Status [closed]
- Random disappearance of footer widgets [closed]
- How to add an image as a bullet point in a specific WordPress widget? [closed]
- Text Widget Not Working
- how to add multiple menu in custom menu widget?