Skip to content

Instantly share code, notes, and snippets.

@finalwebsites
Last active September 1, 2023 10:51
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 finalwebsites/010dc12cc08c097953192a8241f5ae2a to your computer and use it in GitHub Desktop.
Save finalwebsites/010dc12cc08c097953192a8241f5ae2a to your computer and use it in GitHub Desktop.
Add the shortcode option to dynamic tags for background images in Elementor
<?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' );
});
@finalwebsites
Copy link
Author

This code adds the missing option

desktop_Selection_608

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment