Skip to content

Text Control

Elementor Core BasicText Control

Elementor text control displays a simple text input field.

The control is defined in Control_Text class which extends Base_Data_Control class.

Text Control - block view

When using this control, the type should be set to \Elementor\Controls_Manager::TEXT constant.

Arguments

NameTypeDefaultDescription
typestringtextThe type of the control.
labelstringThe label that appears above of the field.
descriptionstringThe description that appears below the field.
show_labelbooltrueWhether to display the label.
label_blockboolfalseWhether to display the label in a separate line.
separatorstringdefaultSet the position of the control separator. Available values are default, before and after. default will hide the separator, unless the control type has specific separator settings. before / after will position the separator before/after the control.
input_typestringtextThe input field type. Available values are all HTML5 supported types.
placeholderstringThe field placeholder that appears when the field has no values.
titlestringThe field title that appears on mouse hover.
classesstringAdd custom classes to control wrapper in the panel.
defaultstringThe field default value.

Return Value

(string) The text field value.

Usage

php
<?php
class Elementor_Test_Widget extends \Elementor\Widget_Base {

	protected function register_controls(): void {

		$this->start_controls_section(
			'content_section',
			[
				'label' => esc_html__( 'Content', 'textdomain' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'widget_title',
			[
				'label' => esc_html__( 'Title', 'textdomain' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'default' => esc_html__( 'Default title', 'textdomain' ),
				'placeholder' => esc_html__( 'Type your title here', 'textdomain' ),
			]
		);

		$this->end_controls_section();

	}

	protected function render(): void {
		$settings = $this->get_settings_for_display();

		if ( empty( $settings['widget_title'] ) ) {
			return;
		}
		?>
		<h2 class="title">
			<?php echo $settings['widget_title']; ?>
		</h2>
		<?php
	}

	protected function content_template(): void {
		?>
		<#
		if ( '' === settings.widget_title ) {
			return;
		}
		#>
		<h2 class="title">
			{{{ settings.widget_title }}}
		</h2>
		<?php
	}

}