Last updated on October 18, 2023

Elementor missing control settings

Don’t know where to add this snippet? Read our guide: How to add code snippets.

Retrieve missing control settings in Elementor.

The Elementor plugin for WordPress provides a wide range of control settings that allow you to customize the appearance and behavior of your website elements. However, there may be cases where you need additional control settings that are not available out of the box. In such situations, you can use custom PHP functions and the Elementor API to add missing control settings.

To add a missing control setting in Elementor, you can use the add_control() method provided by the Widget_Base class. This method allows you to add new control settings to your Elementor widgets.

Here’s an example code snippet that demonstrates how to add a missing control setting for a custom Elementor widget:

<?php
use ElementorControls_Manager;

class My_Custom_Widget extends ElementorWidget_Base {
    // Widget code goes here...

    protected function _register_controls() {
        $this->start_controls_section(
            'section_custom',
            [
                'label' => __( 'Custom Settings', 'text-domain' ),
            ]
        );

        $this->add_control(
            'custom_setting',
            [
                'label' => __( 'Custom Setting', 'text-domain' ),
                'type' => Controls_Manager::TEXT,
                'default' => '',
                'placeholder' => __( 'Enter your custom setting', 'text-domain' ),
            ]
        );

        $this->end_controls_section();
    }

    // Widget code continues...
}

In the above code snippet, we define a custom widget called My_Custom_Widget that extends the Widget_Base class provided by Elementor. Inside the _register_controls() method, we use the add_control() method to add a new control setting called custom_setting. This control setting is of type TEXT and has a default value and a placeholder.

You can modify this code snippet according to your specific requirements by changing the widget class name, control setting label, type, default value, and placeholder.

By adding missing control settings using the add_control() method, you can enhance the functionality of your Elementor widgets and provide more customization options to your users.

Examples

Example #1: Adding Custom Control Settings to Elementor

This use case demonstrates how to add custom control settings to Elementor using the elementor/controls/controls_registered filter hook.

function wpsnippets_add_custom_control_settings( $controls_registry ) {
    $controls_registry->register_control( 'custom-control', [
        'label' => __( 'Custom Control', 'text-domain' ),
        'type' => 'custom-control',
        'section' => 'section_id',
        'settings' => [
            'custom_setting' => [
                'label' => __( 'Custom Setting', 'text-domain' ),
                'type' => ElementorControls_Manager::TEXT,
                'default' => '',
            ],
        ],
    ] );
}
add_action( 'elementor/controls/controls_registered', 'wpsnippets_add_custom_control_settings' );

This code example adds a custom control setting called “Custom Control” to Elementor. The control is of type custom-control and is added to a specific section with the ID section_id. The control has a single setting called “Custom Setting” which is a text input field.

Example #2: Modifying Existing Control Settings in Elementor

This use case demonstrates how to modify existing control settings in Elementor using the elementor/controls/controls_registered filter hook.

function wpsnippets_modify_existing_control_settings( $controls_registry ) {
    $control = $controls_registry->get_control( 'existing-control' );
    if ( $control ) {
        $control->add_control(
            'new_setting',
            [
                'label' => __( 'New Setting', 'text-domain' ),
                'type' => ElementorControls_Manager::SELECT,
                'options' => [
                    'option1' => __( 'Option 1', 'text-domain' ),
                    'option2' => __( 'Option 2', 'text-domain' ),
                ],
                'default' => 'option1',
            ]
        );
    }
}
add_action( 'elementor/controls/controls_registered', 'wpsnippets_modify_existing_control_settings' );

This code example modifies an existing control setting called “Existing Control” in Elementor. It adds a new setting called “New Setting” to the control, which is a select dropdown with two options: “Option 1” and “Option 2”. The default value for the new setting is set to “Option 1”.

Example #3: Removing Control Settings from Elementor

This use case demonstrates how to remove control settings from Elementor using the elementor/controls/controls_registered filter hook.

function wpsnippets_remove_control_settings( $controls_registry ) {
    $controls_registry->unregister_control( 'unwanted-control' );
}
add_action( 'elementor/controls/controls_registered', 'wpsnippets_remove_control_settings' );

This code example removes a control setting called “Unwanted Control” from Elementor. The unregister_control() method is used to unregister the control from the controls registry, effectively removing it from Elementor’s control settings.

Last updated on October 18, 2023. Originally posted on December 15, 2023.

Leave a Reply