Get Widget Settings

When an Elementor Widget generates the final HTML displayed in the fronend and in the preview, it first needs to retrieve the data from the controls.

As we need to generate a PHP template using the render() method and a JS template using the _content_template() method, we need to know how each method retrieves data from the controls.

Retrieving JS Settings

With JS templates we don’t really need to retrieve the data using a special function, its done by Elementor for us. The data from the controls stored in the settings variable.

protected function _content_template() {
	?>
	<h3 class="{{{ settings.class }}}">{{{ settings.title }}}</h3>
	<?php
}

Retrieving PHP Settings

When retrieving the data saved by the user we can either retrieve all data from all the controls of a piece of data from a specific control. The data retrieval is done using the get_settings_for_display() method.

Retrieving data from a single control:

protected function render() {
	echo '<h3>' . $this->get_settings_for_display( 'title' ) . '</h3>';
}

But when we need to retrieve data from multiple controls, we can retrieve all the data from all the controls into a single parameter:

protected function render() {
	$settings = $this->get_settings_for_display();
	echo '<h3 class="' . $settings['class'] . '">' . $settings['title'] . '</h3>';
}

In both ways we get the same result, but keep in mind that the second way has performance benefits.

Backwards Compatibility

If your MINIMUM_ELEMENTOR_VERSION constant is lower than 2.0, you should use the get_settings() method which retrieves all the settings instead of get_settings_for_display() which retrieves only active settings that passed all the conditions and rendered shortcodes & dynamic tags.

protected function render() {
	$settings = $this->get_settings_for_display();
	echo '<h3 class="' . $settings['class'] . '">' . $settings['title'] . '</h3>';
}

Note that if your minimum required version is Elementor 2.0 and above we recommend to use get_settings_for_display().

Get The Latest Updates

We have a lot more where that came from! Join 828,441 subscribers who stay ahead of the pack.
By entering your email, you agree to our Terms of Service and Privacy Policy.