if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
* Elementor shortcode widget.
* Elementor widget that insert any shortcodes into the page.
class Widget_Shortcode extends Widget_Base {
* Retrieve shortcode widget name.
* @return string Widget name.
public function get_name() {
* Retrieve shortcode widget title.
* @return string Widget title.
public function get_title() {
return esc_html__( 'Shortcode', 'elementor' );
* Retrieve shortcode widget icon.
* @return string Widget icon.
public function get_icon() {
return 'eicon-shortcode';
* Retrieve the list of keywords the widget belongs to.
* @return array Widget keywords.
public function get_keywords() {
return [ 'shortcode', 'code' ];
* Whether the reload preview is required or not.
* Used to determine whether the reload preview is required.
* @return bool Whether the reload preview is required.
public function is_reload_preview_required() {
public function has_widget_inner_wrapper(): bool {
return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
* Register shortcode widget controls.
* Adds different input fields to allow the user to change and customize the widget settings.
protected function register_controls() {
$this->start_controls_section(
'label' => esc_html__( 'Shortcode', 'elementor' ),
'label' => esc_html__( 'Enter your shortcode', 'elementor' ),
'type' => Controls_Manager::TEXTAREA,
'placeholder' => '[gallery id="123" size="medium"]',
$this->end_controls_section();
* Render shortcode widget output on the frontend.
* Written in PHP and used to generate the final HTML.
protected function render() {
$shortcode = $this->get_settings_for_display( 'shortcode' );
if ( empty( $shortcode ) ) {
$shortcode = do_shortcode( shortcode_unautop( $shortcode ) );
<div class="elementor-shortcode"><?php echo $shortcode; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
* Render shortcode widget as plain content.
* Override the default behavior by printing the shortcode instead of rendering it.
public function render_plain_content() {
// In plain mode, render without shortcode
$this->print_unescaped_setting( 'shortcode' );
* Render shortcode widget output in the editor.
* Written as a Backbone JavaScript template and used to generate the live preview.
protected function content_template() {}