Last active
December 20, 2020 17:39
-
-
Save obiPlabon/8fa9bf72d0e26a93f01ec7815e7a5655 to your computer and use it in GitHub Desktop.
Disable or remove elementor widget from editor panel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Disable elementor registered widget. | |
* | |
* This will disable all WordPress native widgets | |
* | |
* @param \Elementor\Widgets_Manager $widgets_manager Instance of elementor widgets manager | |
* | |
* @author obiPlabon <https://obiPlabon.im> | |
* | |
* @return void | |
*/ | |
add_action( 'elementor/widgets/widgets_registered', function ( $widgets_manager ) { | |
$wp_widgets = [ | |
'wp-widget-pages', | |
'wp-widget-calendar', | |
'wp-widget-archives', | |
'wp-widget-media_audio', | |
'wp-widget-media_image', | |
'wp-widget-media_gallery', | |
'wp-widget-media_video', | |
'wp-widget-meta', | |
'wp-widget-search', | |
'wp-widget-text', | |
'wp-widget-categories', | |
'wp-widget-recent-posts', | |
'wp-widget-recent-comments', | |
'wp-widget-rss', | |
'wp-widget-tag_cloud', | |
'wp-widget-nav_menu', | |
'wp-widget-custom_html', | |
]; | |
foreach ( $wp_widgets as $widget ) { | |
$widgets_manager->unregister_widget_type( $widget ); | |
} | |
} ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Disable elementor registered widget. | |
* | |
* This will remove elemtor widget from the editor panel | |
* as well as the the widget instance will get removed. | |
* And following this method you can disable any elementor widget | |
* including elementor and elementor pro widgets. | |
* | |
* @param \Elementor\Widgets_Manager $widgets_manager Instance of elementor widgets manager | |
* | |
* @author obiPlabon <https://obiPlabon.im> | |
* | |
* @return void | |
*/ | |
add_action( 'elementor/widgets/widgets_registered', function ( $widgets_manager ) { | |
// $widget_name_goes_here could be 'heading', 'text-widget', 'wp-widget-pages' | |
$widgets_manager->unregister_widget_type( $widget_name_goes_here ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@akash0ahammed When have time please check the method definition of
unregister_widget_type
. This method takes only one argument and that means you can provide only one widget name. Either you have to unregister line by line or using a loop like this https://gist.github.com/obiPlabon/8fa9bf72d0e26a93f01ec7815e7a5655#file-elementor-disable-all-wp-widgets-php