Skip to content

Instantly share code, notes, and snippets.

@dexit
Forked from finalwebsites/shortcode_image_tag.php
Created July 25, 2025 10:11
Show Gist options
  • Save dexit/fad519b4d8eb3ed82dfc7011988ea612 to your computer and use it in GitHub Desktop.
Save dexit/fad519b4d8eb3ed82dfc7011988ea612 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' );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment