• Join the Best Wordpress and Elementor Support forum

    Provide or get advice on everything Elementor and Wordpress, ask questions, gain confirmation or just become apart of a friendly, like minded community who love Wordpress and Elementor


    Join us!

Image Widget - Dynamic - Shortcode not working

M

mw108

New Member
Hello,

I want to display an image via a custom shortcode:

Zwischenablage01.jpg


But it isn't working. There is simply nothing displayed. Neither in the editor, nor in the front end. Also not if I remove the brackets [ ... ] around the shortcode and try "brand_banner" only.

However, if I use a simple text editor widget and put the shortcode in, it works as expected.

Zwischenablage02.jpg


This is the code for the shortcode:
PHP:
public function shortcode_brand_banner( $atts ) {
    $brand = $this->getRandomBrandFromPool();

    $variantIndex = 1;
    $variantLabel = [ '0', 'a', 'b', 'c' ];

    // Return the rendered image HTML.
    return ( types_render_field( 'image-brand-' . $variantLabel[ $variantIndex ], [ 'post_id' => $brand->post->ID ] ) );
}

I thought maybe it is because it doesn't expect rendered image HTML, but only an image URL. So I changed the code to this, but it doesn't work either:
PHP:
public function shortcode_brand_banner( $atts ) {
    $brand = $this->getRandomBrandFromPool();

    $variantIndex = 1;
    $variantLabel = [ '0', 'a', 'b', 'c' ];

    // Only return image URL.
    $image = get_post_meta( $brand->post->ID, 'wpcf-image-brand-' . $variantLabel[ $variantIndex ] )[ 0 ];
    return ( $image );
}

So, what am I doing wrong here? How can I display an image via Dynamic Shortcode? :)

Thank you!
 

Latest Resources

Other Elementor Resources

elementor official

Still stuck? Ask the forum

Post your question with a screenshot and a link if you can, and a member will usually reply within a day. Free to join, no sales pitch.

Create a free account
Top