Skip to content

Instantly share code, notes, and snippets.

@obiPlabon
Last active December 20, 2020 17:39
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save obiPlabon/8fa9bf72d0e26a93f01ec7815e7a5655 to your computer and use it in GitHub Desktop.
Save obiPlabon/8fa9bf72d0e26a93f01ec7815e7a5655 to your computer and use it in GitHub Desktop.
Disable or remove elementor widget from editor panel
<?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 );
} );
@obiPlabon
Copy link
Author

obiPlabon commented Dec 12, 2020

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 😉

Object.keys(ElementorConfig.initial_document.widgets).filter(name => name.startsWith('wp-'))

@akash0ahammed
Copy link

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.

@obiPlabon
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment