
Community
Administrator
Staff member
To disable specific Elementor widgets using the elementor/widgets/register hook, follow these steps:
This example disables the advanced-heading widget for non-administrators.
Step-by-Step Explanation:
- Identify Widget IDs: Determine the IDs of the widgets you want to disable. These can be found by inspecting the widget's data-widget-type attribute in the Elementor editor using browser developer tools.
- Hook into Widget Registration: Use the elementor/widgets/register hook with a priority higher than default (e.g., 15) to ensure widgets are registered before attempting to unregister them.
- Unregister Widgets: In your callback function, use the unregister() method of the Widgets_Manager to remove each specified widget by its ID.
Example Code:
Add the following code to your theme's functions.php file or a custom plugin: PHP:
add_action( 'elementor/widgets/register', 'disable_specific_elementor_widgets', 15 );
function disable_specific_elementor_widgets( $widgets_manager ){$widget_ids = [
'heading',
'image-carousel',
'audio', // Elementor Audio Widget (if available)
];
foreach ( $widget_ids as $widget_id ){$widgets_manager->unregister( $widget_id );
}
}
Notes:
- Widget IDs: Replace the example widget IDs (heading, image-carousel, etc.) with the IDs of the widgets you want to disable.
- Priority: The priority 15 ensures the hook runs after Elementor registers its default widgets (which happens at priority 10).
- Existing Content: This only prevents new instances of the widget from being added; existing widget instances on pages/posts remain unaffected.
Finding Widget IDs:
- In Elementor Editor:
- Open a page in the Elementor editor.
- Right-click a widget in the panel and select "Inspect".
- Look for the data-widget-type attribute in the HTML (e.g., data-widget-type="heading").
- Third-Party Widgets:
- For plugins or Elementor Pro widgets, use the same method to find their unique IDs.
Advanced Usage:
To conditionally disable widgets (e.g., for specific user roles),modify the callback function: PHP:
function disable_specific_elementor_widgets( $widgets_manager ){if ( ! current_user_can( 'administrator' ) ){$widgets_manager->unregister( 'advanced-heading' );
}
}