• Join the Best Wordpress and Elementor Support forum

    Provide or get advice on everything Elementor and Wordpress, ask questions, gain confirmation or just become apart of a friendly, like minded community who love Wordpress and Elementor


    Join us!

How to disable specific Elementor widgets using the elementor/widgets/register hook?

Community

Community

Administrator
Staff member
To disable specific Elementor widgets using the elementor/widgets/register hook, follow these steps:

Step-by-Step Explanation:​

  1. 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.
  2. 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.
  3. 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 ) {
    // List of widget IDs to disable
    $widget_ids = [
        'heading',              // Elementor Heading Widget
        'image-carousel',       // Elementor Image Carousel Widget
        'audio',                // Elementor Audio Widget (if available)
        // Add more widget IDs here
    ];

    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:​

  1. 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").
  2. 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' );
    }
}
This example disables the advanced-heading widget for non-administrators.
 

Latest Resources

Other Elementor Resources

elementor official

Still stuck? Ask the forum

Post your question with a screenshot and a link if you can, and a member will usually reply within a day. Free to join, no sales pitch.

Create a free account
Top