Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to hide some Elementor Pro widgets from the frontend editor? #3136

Closed
stratboy opened this issue Jan 10, 2018 · 22 comments
Closed

How to hide some Elementor Pro widgets from the frontend editor? #3136

stratboy opened this issue Jan 10, 2018 · 22 comments

Comments

@stratboy
Copy link
Contributor

@stratboy stratboy commented Jan 10, 2018

Hi, I would like to clean up the editor since most of the time we use just the 10% of all widgets.

I learned how to unregister default Elementor widgets with $widgets_manager->unregister_widget_type, but it seems it doesn't work for Elementor Pro widgets: they seem to be 'modules' rather than 'widgets'.

How to?

@stratboy
Copy link
Contributor Author

@stratboy stratboy commented Jan 10, 2018

By the way, it should be somewhat easier to hide widgets. Maybe a checkbox list in preferences? Or simply make the widgets lists collapsable (and saving layout prefs)?

@bainternet
Copy link
Collaborator

@bainternet bainternet commented Jan 11, 2018

You can use $widgets_manager->unregister_widget_type to remove any Elementor, Elementor Pro or any other 3rd party plugin widgets that are registered (assuming its done correctly), you simply need to make sure are already registered before you remove them.

The Pro widgets are registered on default priority which is 10 so you just make sure you run your hook after that for example with priority of 15:

add_action('elementor/widgets/widgets_registered', function( $widget_manager ){
	$widget_manager->unregister_widget_type('form');
}, 15);

@stratboy
Copy link
Contributor Author

@stratboy stratboy commented Jan 11, 2018

Ok done for pro widgets too. Still can't hide the wordpress widgets since I can't find a list of wp widgets names. How to?

@norewp
Copy link

@norewp norewp commented Jan 19, 2018

@stratboy - This might help. Note however that the function removes all WP Widgets as opposed to individual.

https://github.com/norewp/unregister-elementor-widgets/blob/584252abebe56d9b45fb8bc2d46fe15945400b44/modules/unregister/module.php#L38

If you know the widget's id_base then you can simply use the same method for Elementor by simply appending the id to the name in place of the variable shown at L42

@stratboy
Copy link
Contributor Author

@stratboy stratboy commented Jan 30, 2018

@norewp - thank you. The following is sample code for removing everything (for now > I suppose in the future there will be some other widgets). To activate the ones needed, just comment out the corresponding array items.

global $elementor_widget_blacklist;

$elementor_widget_blacklist = [
  ,'common'
  ,'heading'
  ,'image'
  ,'text-editor'
  ,'video'
  ,'button'
  ,'divider'
  ,'spacer'
  ,'image-box'
  ,'google-maps'
  ,'icon'
  ,'icon-box'
  ,'image-gallery'
  ,'image-carousel'
  ,'icon-list'
  ,'counter'
  ,'progress'
  ,'testimonial'
  ,'tabs'
  ,'accordion'
  ,'toggle'
  ,'social-icons'
  ,'alert'
  ,'audio'
  ,'shortcode'
  ,'html'
  ,'menu-anchor'
  ,'sidebar'

  // pro ----------------- //
  ,'posts'
  ,'portfolio'
  ,'slides'
  ,'form'
  ,'login'
  ,'media-carousel'
  ,'testimonial-carousel'
  ,'nav-menu'
  ,'pricing'
  ,'facebook-comment'
  ,'nav-menu'
  ,'animated-headline'
  ,'price-list'
  ,'price-table'
  ,'facebook-button'
  ,'facebook-comments'
  ,'facebook-embed'
  ,'facebook-page'
  ,'add-to-cart'
  ,'categories'
  ,'elements'
  ,'products'
  ,'flip-box'
  ,'carousel'
  ,'countdown'
  ,'share-buttons'
  ,'author-box'
  ,'breadcrumbs'
  ,'search-form'
  ,'post-navigation'
  ,'post-comments'
  ,'theme-elements'
  ,'blockquote'
  ,'template'
  ,'wp-widget-audio'
  ,'woocommerce'
  ,'social'
  ,'library'

  // wp widgets ----------------- //
  ,'wp-widget-pages'
  ,'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'
  ,'wp-widget-polylang'
  ,'wp-widget-calendar'
  ,'wp-widget-elementor-library'
];

add_action('elementor/widgets/widgets_registered', function($widgets_manager){
  global $elementor_widget_blacklist;

  foreach($elementor_widget_blacklist as $widget_name){
    $widgets_manager->unregister_widget_type($widget_name);
  }
}, 15);

@gianghl1983
Copy link

@gianghl1983 gianghl1983 commented Sep 23, 2018

Beside clearer editor, do we have any another benifit from removing widgets? (lighter js, faster...)?

@madbradj
Copy link

@madbradj madbradj commented Aug 21, 2019

@norewp - thank you. The following is sample code for removing everything (for now > I suppose in the future there will be some other widgets). To activate the ones needed, just comment out the corresponding array items.

Does this stop the corresponding CSS/js etc from loading?

@websitehelperuk
Copy link

@websitehelperuk websitehelperuk commented Dec 10, 2019

Will this have any performance benefits? I want to remove and dequeue as much as possible.

@webkonditorei
Copy link

@webkonditorei webkonditorei commented Jan 24, 2020

Where do I add this code?...

@Dadparvar
Copy link

@Dadparvar Dadparvar commented May 23, 2020

Where do I add this code?...

functions.php file of your theme.

@Noeil182
Copy link

@Noeil182 Noeil182 commented May 29, 2020

@norewp - thank you. The following is sample code for removing everything (for now > I suppose in the future there will be some other widgets). To activate the ones needed, just comment out the corresponding array items.

global $elementor_widget_blacklist;

$elementor_widget_blacklist = [
  ,'common'
  ,'heading'
  ,'image'
  ,'text-editor'
  ,'video'
  ,'button'
  ,'divider'
  ,'spacer'
  ,'image-box'
  ,'google-maps'
  ,'icon'
  ,'icon-box'
  ,'image-gallery'
  ,'image-carousel'
  ,'icon-list'
  ,'counter'
  ,'progress'
  ,'testimonial'
  ,'tabs'
  ,'accordion'
  ,'toggle'
  ,'social-icons'
  ,'alert'
  ,'audio'
  ,'shortcode'
  ,'html'
  ,'menu-anchor'
  ,'sidebar'

  // pro ----------------- //
  ,'posts'
  ,'portfolio'
  ,'slides'
  ,'form'
  ,'login'
  ,'media-carousel'
  ,'testimonial-carousel'
  ,'nav-menu'
  ,'pricing'
  ,'facebook-comment'
  ,'nav-menu'
  ,'animated-headline'
  ,'price-list'
  ,'price-table'
  ,'facebook-button'
  ,'facebook-comments'
  ,'facebook-embed'
  ,'facebook-page'
  ,'add-to-cart'
  ,'categories'
  ,'elements'
  ,'products'
  ,'flip-box'
  ,'carousel'
  ,'countdown'
  ,'share-buttons'
  ,'author-box'
  ,'breadcrumbs'
  ,'search-form'
  ,'post-navigation'
  ,'post-comments'
  ,'theme-elements'
  ,'blockquote'
  ,'template'
  ,'wp-widget-audio'
  ,'woocommerce'
  ,'social'
  ,'library'

  // wp widgets ----------------- //
  ,'wp-widget-pages'
  ,'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'
  ,'wp-widget-polylang'
  ,'wp-widget-calendar'
  ,'wp-widget-elementor-library'
];

add_action('elementor/widgets/widgets_registered', function($widgets_manager){
  global $elementor_widget_blacklist;

  foreach($elementor_widget_blacklist as $widget_name){
    $widgets_manager->unregister_widget_type($widget_name);
  }
}, 15);

I pasted the code in my functions.php file but I got the following error. Am I missing something? Thanks!
2020-05-29_0039

@tiflopin
Copy link

@tiflopin tiflopin commented Jun 5, 2020

@Noeil182 The first line of the $elementor_widget_blacklist array should not start with a coma.

Here ,'common' should be 'common'

This should work :

global $elementor_widget_blacklist;

$elementor_widget_blacklist = [
  'common'
  ,'heading'
  ,'image'
  ,'text-editor'
  ,'video'
  ,'button'
  ,'divider'
  ,'spacer'
  ,'image-box'
  ,'google-maps'
  ,'icon'
  ,'icon-box'
  ,'image-gallery'
  ,'image-carousel'
  ,'icon-list'
  ,'counter'
  ,'progress'
  ,'testimonial'
  ,'tabs'
  ,'accordion'
  ,'toggle'
  ,'social-icons'
  ,'alert'
  ,'audio'
  ,'shortcode'
  ,'html'
  ,'menu-anchor'
  ,'sidebar'

  // pro ----------------- //
  ,'posts'
  ,'portfolio'
  ,'slides'
  ,'form'
  ,'login'
  ,'media-carousel'
  ,'testimonial-carousel'
  ,'nav-menu'
  ,'pricing'
  ,'facebook-comment'
  ,'nav-menu'
  ,'animated-headline'
  ,'price-list'
  ,'price-table'
  ,'facebook-button'
  ,'facebook-comments'
  ,'facebook-embed'
  ,'facebook-page'
  ,'add-to-cart'
  ,'categories'
  ,'elements'
  ,'products'
  ,'flip-box'
  ,'carousel'
  ,'countdown'
  ,'share-buttons'
  ,'author-box'
  ,'breadcrumbs'
  ,'search-form'
  ,'post-navigation'
  ,'post-comments'
  ,'theme-elements'
  ,'blockquote'
  ,'template'
  ,'wp-widget-audio'
  ,'woocommerce'
  ,'social'
  ,'library'

  // wp widgets ----------------- //
  ,'wp-widget-pages'
  ,'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'
  ,'wp-widget-polylang'
  ,'wp-widget-calendar'
  ,'wp-widget-elementor-library'
];

add_action('elementor/widgets/widgets_registered', function($widgets_manager){
  global $elementor_widget_blacklist;

  foreach($elementor_widget_blacklist as $widget_name){
    $widgets_manager->unregister_widget_type($widget_name);
  }
}, 15);

@Noeil182
Copy link

@Noeil182 Noeil182 commented Jun 8, 2020

Thanks for your help!

@solace
Copy link

@solace solace commented Sep 10, 2020

Hi,

Just checking, should this still work for pro widgets? They still display in the editor panel, and the widget list doesn't appear to contain any of the items in the pro section at the time the action is hit.

@nicmare
Copy link

@nicmare nicmare commented Nov 4, 2020

the code works for wp- elements only. pro items still appear. are there any changes since v3?

@mhason
Copy link

@mhason mhason commented Nov 15, 2020

@Noeil182 The first line of the $elementor_widget_blacklist array should not start with a coma.

Here ,'common' should be 'common'

This should work :

global $elementor_widget_blacklist;

$elementor_widget_blacklist = [
  'common'
  ,'heading'
  ,'image'
  ,'text-editor'
  ,'video'
  ,'button'
  ,'divider'
  ,'spacer'
  ,'image-box'
  ,'google-maps'
  ,'icon'
  ,'icon-box'
  ,'image-gallery'
  ,'image-carousel'
  ,'icon-list'
  ,'counter'
  ,'progress'
  ,'testimonial'
  ,'tabs'
  ,'accordion'
  ,'toggle'
  ,'social-icons'
  ,'alert'
  ,'audio'
  ,'shortcode'
  ,'html'
  ,'menu-anchor'
  ,'sidebar'

  // pro ----------------- //
  ,'posts'
  ,'portfolio'
  ,'slides'
  ,'form'
  ,'login'
  ,'media-carousel'
  ,'testimonial-carousel'
  ,'nav-menu'
  ,'pricing'
  ,'facebook-comment'
  ,'nav-menu'
  ,'animated-headline'
  ,'price-list'
  ,'price-table'
  ,'facebook-button'
  ,'facebook-comments'
  ,'facebook-embed'
  ,'facebook-page'
  ,'add-to-cart'
  ,'categories'
  ,'elements'
  ,'products'
  ,'flip-box'
  ,'carousel'
  ,'countdown'
  ,'share-buttons'
  ,'author-box'
  ,'breadcrumbs'
  ,'search-form'
  ,'post-navigation'
  ,'post-comments'
  ,'theme-elements'
  ,'blockquote'
  ,'template'
  ,'wp-widget-audio'
  ,'woocommerce'
  ,'social'
  ,'library'

  // wp widgets ----------------- //
  ,'wp-widget-pages'
  ,'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'
  ,'wp-widget-polylang'
  ,'wp-widget-calendar'
  ,'wp-widget-elementor-library'
];

add_action('elementor/widgets/widgets_registered', function($widgets_manager){
  global $elementor_widget_blacklist;

  foreach($elementor_widget_blacklist as $widget_name){
    $widgets_manager->unregister_widget_type($widget_name);
  }
}, 15);

Adding this spits out the following error:

Screen Shot 2020-11-15 at 20 49 40

@thisearlyseason
Copy link

@thisearlyseason thisearlyseason commented Dec 9, 2020

Any updates about this? I dont know where to place this within the functions.php file

@erwinfrancis
Copy link

@erwinfrancis erwinfrancis commented Apr 4, 2021

This is not working

@erwinfrancis
Copy link

@erwinfrancis erwinfrancis commented Apr 4, 2021

This works for me and apparently you can't unregister everything especially 'common' or it will throw a critical error. Just comment or delete those you want to keep.

add_action('elementor/widgets/widgets_registered', function($widgets_manager){

$widgets_manager->unregister_widget_type('heading');
$widgets_manager->unregister_widget_type('image');
$widgets_manager->unregister_widget_type('text-editor');
$widgets_manager->unregister_widget_type('video');
$widgets_manager->unregister_widget_type('button');
$widgets_manager->unregister_widget_type('divider');
$widgets_manager->unregister_widget_type('spacer');
$widgets_manager->unregister_widget_type('image-box');
$widgets_manager->unregister_widget_type('google-maps');
$widgets_manager->unregister_widget_type('icon');
$widgets_manager->unregister_widget_type('icon-box');
$widgets_manager->unregister_widget_type('image-gallery');
$widgets_manager->unregister_widget_type('image-carousel');
$widgets_manager->unregister_widget_type('icon-list');
$widgets_manager->unregister_widget_type('counter');
$widgets_manager->unregister_widget_type('progress');
$widgets_manager->unregister_widget_type('testimonial');
$widgets_manager->unregister_widget_type('tabs');
$widgets_manager->unregister_widget_type('accordion');
$widgets_manager->unregister_widget_type('toggle');
$widgets_manager->unregister_widget_type('social-icons');
$widgets_manager->unregister_widget_type('alert');
$widgets_manager->unregister_widget_type('audio');
$widgets_manager->unregister_widget_type('shortcode');
$widgets_manager->unregister_widget_type('html');
$widgets_manager->unregister_widget_type('menu-anchor');
$widgets_manager->unregister_widget_type('sidebar');

// pro ----------------- //
$widgets_manager->unregister_widget_type('posts');
$widgets_manager->unregister_widget_type('portfolio');
$widgets_manager->unregister_widget_type('slides');
$widgets_manager->unregister_widget_type('form');
$widgets_manager->unregister_widget_type('login');
$widgets_manager->unregister_widget_type('media-carousel');
$widgets_manager->unregister_widget_type('testimonial-carousel');
$widgets_manager->unregister_widget_type('nav-menu');
$widgets_manager->unregister_widget_type('pricing');
$widgets_manager->unregister_widget_type('facebook-comment');
$widgets_manager->unregister_widget_type('nav-menu');
$widgets_manager->unregister_widget_type('animated-headline');
$widgets_manager->unregister_widget_type('price-list');
$widgets_manager->unregister_widget_type('price-table');
$widgets_manager->unregister_widget_type('facebook-button');
$widgets_manager->unregister_widget_type('facebook-comments');
$widgets_manager->unregister_widget_type('facebook-embed');
$widgets_manager->unregister_widget_type('facebook-page');
$widgets_manager->unregister_widget_type('add-to-cart');
$widgets_manager->unregister_widget_type('categories');
$widgets_manager->unregister_widget_type('elements');
$widgets_manager->unregister_widget_type('products');
$widgets_manager->unregister_widget_type('flip-box');
$widgets_manager->unregister_widget_type('carousel');
$widgets_manager->unregister_widget_type('countdown');
$widgets_manager->unregister_widget_type('share-buttons');
$widgets_manager->unregister_widget_type('author-box');
$widgets_manager->unregister_widget_type('breadcrumbs');
$widgets_manager->unregister_widget_type('search-form');
$widgets_manager->unregister_widget_type('post-navigation');
$widgets_manager->unregister_widget_type('post-comments');
$widgets_manager->unregister_widget_type('theme-elements');
$widgets_manager->unregister_widget_type('blockquote');
$widgets_manager->unregister_widget_type('template');
$widgets_manager->unregister_widget_type('wp-widget-audio');
$widgets_manager->unregister_widget_type('woocommerce');
$widgets_manager->unregister_widget_type('social');
$widgets_manager->unregister_widget_type('library');

// wp widgets ----------------- //
$widgets_manager->unregister_widget_type('wp-widget-pages');
$widgets_manager->unregister_widget_type('wp-widget-archives');
$widgets_manager->unregister_widget_type('wp-widget-media_audio');
$widgets_manager->unregister_widget_type('wp-widget-media_image');
$widgets_manager->unregister_widget_type('wp-widget-media_gallery');
$widgets_manager->unregister_widget_type('wp-widget-media_video');
$widgets_manager->unregister_widget_type('wp-widget-meta');
$widgets_manager->unregister_widget_type('wp-widget-search');
$widgets_manager->unregister_widget_type('wp-widget-text');
$widgets_manager->unregister_widget_type('wp-widget-categories');
$widgets_manager->unregister_widget_type('wp-widget-recent-posts');
$widgets_manager->unregister_widget_type('wp-widget-recent-comments');
$widgets_manager->unregister_widget_type('wp-widget-rss');
$widgets_manager->unregister_widget_type('wp-widget-tag_cloud');
$widgets_manager->unregister_widget_type('wp-widget-nav_menu');
$widgets_manager->unregister_widget_type('wp-widget-custom_html');
$widgets_manager->unregister_widget_type('wp-widget-polylang');
$widgets_manager->unregister_widget_type('wp-widget-calendar');
$widgets_manager->unregister_widget_type('wp-widget-elementor-library');

}, 15);

@yuenjian
Copy link

@yuenjian yuenjian commented Apr 8, 2021

This code works great. But found that some woocommerce widgets are not being removed from the wordpress dropdown widget.

is there a way to unregister those as well? Just unregister it from elementor, not totally unregister from wordpress.

Elementor-Outlets

@seaware
Copy link

@seaware seaware commented May 20, 2021

Sorry I'm coming late to the party here. What's the best place for this code to help ensure elementor has them registered before they're removed? I'm new to WP code. I added the code above to functions.php but it doesn't do anything because it seems to be too early.

@rafaelhsouza-dev
Copy link

@rafaelhsouza-dev rafaelhsouza-dev commented May 26, 2021

functions.php

function hide_widgets_elementor_pro() {
echo '<style>
#elementor-panel-category-pro-elements, #elementor-panel-category-woocommerce-elements, #elementor-panel-category-theme-elements, #elementor-panel-get-pro-elements, .elementor-nerd-box{
display: none !important;
}
</style>';
}
add_action('admin_init', 'hide_widgets_elementor_pro');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet