Skip to content

Instantly share code, notes, and snippets.

@bainternet
Forked from dtbaker/code.php
Created December 7, 2017 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bainternet/136f6461da028c0d681416a57c510032 to your computer and use it in GitHub Desktop.
Save bainternet/136f6461da028c0d681416a57c510032 to your computer and use it in GitHub Desktop.
Add a custom control to an existing Elementor widget
<?php
// This example will add a custom "select" drop down to the "Image Box"
// This will change the class="" on the rendered image box so we can style the Image Box differently
// based on the selected option from the editor.
// The class will be "my-image-box-style-blue" or "my-image-box-style-green" based on the selected option.
add_action('elementor/element/before_section_end', function( $section, $section_id, $args ) {
if( $section->get_name() == 'image-box' && $section_id == 'section_image' ){
// we are at the end of the "section_image" area of the "image-box"
$section->add_control(
'my_custom_control' ,
[
'label' => 'My Label Here',
'type' => Elementor\Controls_Manager::SELECT,
'default' => 'blue',
'options' => array( 'blue' => 'Blue Style', 'green' => 'Green Style' ),
'prefix_class' => 'my-image-box-style-',
'label_block' => true,
]
);
}
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment