-
-
Save obiPlabon/8fa9bf72d0e26a93f01ec7815e7a5655 to your computer and use it in GitHub Desktop.
<?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 ); | |
} | |
} ); |
<?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 ); | |
} ); |
Bro, In function.php I pasted the codes for testing purposes.
// First Attemt:
add_action( 'elementor/widgets/widgets_registered', function ( $widgets_manager ) {
$widgets_manager->unregister_widget_type( 'image-box' , 'image-carousel' , 'image-gallery' ,);
} );
// Only the Image box got hidden, Other widgets are still visible.
// Second attempt to see if one by one is possible to hide or not. Yes, the below code worked. How can I make the first attempt code to work? I have zero skills in PHP.
add_action( 'elementor/widgets/widgets_registered', function ( $widgets_manager ) {
$widgets_manager->unregister_widget_type( 'image-gallery');
} );
Thank you for this awesome snippet.
@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
If you are wondering whether I typed those widgets name manually or not then please open your Elementor editor and paste the following code in your browser (chrome) console see the magic 😉