Image Widget Dynamic Shortcode: No output
-
I’m using Elementor Pro and want to display an image via a custom shortcode as displayed here: https://docs.elementor.com/article/449-dynamic-shortcode
https://i.stack.imgur.com/dTKU8.jpg
But it isn’t working. There is simply nothing displayed. Neither in the editor, nor in the frontend. Also not if I remove the brackets
[ ... ]
around the shortcode and trybrand_banner
only.It does not produce any DOM output in the frontend, just an empty
elementor-widget-wrap
div
:<div class="elementor-element elementor-element-4f1547ad elementor-column elementor-col-50 elementor-inner-column" data-id="4f1547ad" data-element_type="column"> <div class="elementor-column-wrap elementor-element-populated"> <div class="elementor-widget-wrap"> </div> </div> </div>
However, if I use a simple text editor widget and put the shortcode in, it works as expected:
https://i.stack.imgur.com/uBf16.jpg
DOM:
<div class="elementor-element elementor-element-37728dd elementor-widget elementor-widget-text-editor" data-id="37728dd" data-element_type="widget" data-widget_type="text-editor.default"> <div class="elementor-widget-container"> <div class="elementor-text-editor elementor-clearfix"> <img src="https://some.domain.com/wp-content/uploads/banner-a.jpg"></div> </div> </div> </div>
This is the code for the shortcode:
public function shortcode_brand_banner( $atts ) { $brand = $this->getRandomBrandFromPool(); // Return the rendered image HTML. return ( types_render_field( 'image-brand-banner', [ 'post_id' => $brand->post->ID ] ) ); }
I thought maybe it is because it doesn’t expect HTML, but rather an image URL. So I changed the code to this, but it doesn’t work either:
public function shortcode_brand_banner( $atts ) { $brand = $this->getRandomBrandFromPool(); // Only return image URL like "https://some.domain.com/wp-content/uploads/banner-a.jpg" $image = get_post_meta( $brand->post->ID, 'wpcf-image-brand-banner' )[ 0 ]; return ( $image ); }
What is the problem here? Is this a bug in Elementor Pro? What kind of output does the Widget expect?
- The topic ‘Image Widget Dynamic Shortcode: No output’ is closed to new replies.