Last active
September 1, 2023 10:51
-
-
Save finalwebsites/010dc12cc08c097953192a8241f5ae2a to your computer and use it in GitHub Desktop.
Add the shortcode option to dynamic tags for background images in Elementor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// place the snippet inside the functions.php file from your WordPress child theme | |
use Elementor\Controls_Manager; | |
add_action( 'elementor/dynamic_tags/register_tags', function( $dynamic_tags ) { | |
class Custom_Image_Tag extends Elementor\Core\DynamicTags\Data_Tag { | |
public function get_name() { | |
return 'shortcode-image'; | |
} | |
public function get_categories() { | |
return [ 'image' ]; | |
} | |
public function get_group() { | |
return [ 'site' ]; | |
} | |
public function get_title() { | |
return 'Shortcode Image'; | |
} | |
protected function _register_controls() { | |
$this->add_control( | |
'shortcode', | |
[ | |
'label' => __( 'Shortcode', 'elementor-pro' ), | |
'type' => Controls_Manager::TEXTAREA, | |
] | |
); | |
} | |
protected function get_value( array $options = [] ) { | |
$settings = $this->get_settings(); | |
if ( empty( $settings['shortcode'] ) ) { | |
return; | |
} | |
return [ | |
'url' => do_shortcode( $settings['shortcode'] ) // Your shortcode MUST return a full valid URL | |
]; | |
} | |
} | |
$dynamic_tags->register_tag( 'Custom_Image_Tag' ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code adds the missing option