Okay
  Public Ticket #4500026
LayerSlider Dynamic ACF Integration on Single Post Pages
Open

Comments

  • Zoran started the conversation

    Hello,

    I am trying to use LayerSlider dynamically with my custom post type (Vrata) where each single post (door product) has its own content managed with ACF fields.

    >CLEAR IMAGE BASED PROBLEM EXPLANATION LINK

    My goal:

    • On each single Vrata post, display a LayerSlider that pulls the correct door image (PNG) and dynamic text fields from ACF.

    • I want LayerSlider to change based on the current post being viewed (so if post A has a white door and post B has a black door, the slider should reflect that automatically).

    • Ideally, this would allow me to animate the door PNG inside LayerSlider, while still pulling the correct image/text from the current post.

    The issues I am running into:

    1. The [meta:fieldname] placeholder does not properly return the ACF image field value (it either outputs 989 or doesn’t render the image at all).

    2. Using [image] only pulls the featured image, but it seems to always display the same image across different posts, not the correct one for each post.

    3. I tried editing my theme templates (single.php, single-vrata.php) to pass the post_id into the shortcode like this:

      echo do_shortcode('[layerslider id="2" post_id="' . get_the_ID() . '"]');
      

      But my theme (Royal Elementor Kit) seems to ignore these templates and instead relies on Elementor’s Theme Builder for single posts. That means I can’t confirm if LayerSlider is picking up the post context.

    My main question:
    How can I make LayerSlider reliably pull the correct ACF fields (images and text) for the current post being viewed in a Single Post template?

    I need to know if:

    • LayerSlider can directly recognize the current post context when embedded in Elementor’s Single Post template.

    • Or if I must pass the post_id somehow.

    • Or if this is a known limitation and I need a different approach.

    Any guidance or code snippet from your side would help a lot,  I’ve invested in LayerSlider specifically for its animation capabilities, and I just need to connect it properly to my ACF data.

    Thank you in advance for your support!

    Kind regards,
    Zoran

  •  77
    John replied

    Hi Zoran,

    Thank you for reaching out to us. My name is John, and I'm happy to assist you. I sincerely appreciate your patience while we worked to get back to you.

    LayerSlider does not accept a post_id attribute in its shortcode, so you cannot manually pass the context that way. Fortunately, that is not a problem, since the plugin automatically relies on get_the_ID() to determine the current post, and it should already receive the correct post context without any extra configuration.

    The issue comes from how ACF fields are handled. Standard text fields work as expected, but image fields return an attachment ID. LayerSlider does not have built-in logic to turn that ID into a usable image URL, so instead of displaying the image, it shows the raw number or nothing at all. This is simply a limitation of the current version, as there is no dedicated ACF integration yet.

    A practical workaround is to add a small custom shortcode in your theme or a helper plugin. That shortcode can fetch the ACF image field for the current post and return the actual image URL. You can then insert this shortcode in the LayerSlider image or background fields, and it will correctly output the image linked to each post. This way, you can still connect your ACF content with LayerSlider's animation features until native support is available.

    Best Regards,
    John | Kreatura Dev Team

  • Zoran replied

    Hi John,

    Thank you very much for clarifying. That makes sense now ,I see why the [meta:fieldname] placeholder only returns the numeric ID for images.

    I like your suggestion of using a helper shortcode. Could you please confirm if something like this would work?

    function acf_image_url_shortcode($atts) {    $atts = shortcode_atts(        array(            'field' => '',            'size'  => 'full',        ),        $atts    );
        if (empty($atts['field'])) return '';
        $image_id = get_field($atts['field']);    if (!$image_id) return '';
        $image_url = wp_get_attachment_image_url($image_id, $atts['size']);    return esc_url($image_url);
    }
    add_shortcode('acf_image_url', 'acf_image_url_shortcode');
    

    Then in LayerSlider I’d call:

    [acf_image_url field="vrata_slider"]
    

    Would that be the correct approach?

    Also, would this method still respect the current post context automatically, without needing to pass post_id manually?

    Thanks again for your help!

    Kind regards,
    Zoran

  •  77
    John replied

    Yes, that code looks good and it should work as intended. Since ACF's get_field() function pulls data from the current post in the loop, you generally do not need to pass a post ID manually. Because LayerSlider executes the shortcode exactly where you place the slider, the post context of that page will naturally apply.

    To insert the shortcode, you can right-click on LayerSlider's image pickers (e.g., slide background) and choose the "Enter from URL" option. Paste your shortcode there, and it will resolve on the front end when the slider is embedded on the page. Just keep in mind that the result is only visible in the live slider, not inside the editor preview.

    Best Regards,
    John | Kreatura Dev Team

  • Zoran replied

    Hello again,

    I’ve successfully created a shortcode that outputs my ACF image field as an <img> tag. Example:

    function acf_image_url_shortcode($atts) {    $atts = shortcode_atts(        array(            'field' => '',            'size'  => 'full',        ),        $atts    );
        if (empty($atts['field'])) return '';
        $image_id = get_field($atts['field']);    if (!$image_id) return '';
        $image_url = wp_get_attachment_image_url($image_id, $atts['size']);
        // Instead of just URL, return a real IMG tag    return '<img src="' . esc_url($image_url) . '" alt="" />';
    }
    add_shortcode('acf_image_url', 'acf_image_url_shortcode');
    

    When I use it in a LayerSlider Text/Dynamic Layer, it works perfectly:

    [acf_image_url field="vrata_slider"]
    

    However, I cannot use the same logic in Image Layers. LS seems to ignore shortcodes inside media['image'] fields and treats them as plain text, so the image never loads.

    Could you please confirm if LayerSlider officially supports evaluating shortcodes inside image/background fields? Or is a filter like this (running do_shortcode() on media['image']) the only way to make it work?

    This is the final missing piece for making my single CPT pages fully dynamic. Any guidance would be greatly appreciated.

    INSPECT EL. ERROR LOG IMG

    Thank you,
    Zoran

  •  77
    John replied

    You are absolutely right, Zoran. At the moment, shortcodes are evaluated in slide backgrounds, slide thumbnails, and layer backgrounds, but not in image layers. That omission has already been addressed in our development build, and full shortcode support for image layers will be part of the upcoming release.

    This next update is a major one with many new features, so we will first publish it as a beta version even though it is considered stable. If you would like early access, you can switch your release channel to "Beta" in the Plugin Updates box. We plan to make the beta available later this week.

    In the meantime, the workaround you discovered is perfectly valid and produces the same end result as an image layer would. Thank you again for reporting this and for the proactive way you approached the issue. Your solution was spot on!

    Best Regards,
    John | Kreatura Dev Team

  • Zoran replied

    Thank you so much for all your support and the clear explanations throughout this process. It really helped me understand what was going on under the hood with LayerSlider and ACF.

    I’ll keep using the current workaround for now, and I’ll count on the beta release at the end of this week to finally start using dynamic images directly inside image layers across my LayerSlider-powered websites. Really looking forward to testing it out once it drops.

    Thanks again for the assistance and for the proactive improvements you and the team are making to LayerSlider!

    Best regards,
    Zoran

    P.S. Please let me know if the beta timing changes so I can plan around it.

  •  77
    John replied

    Thank you for your kind words, Zoran. We truly appreciate it!

    Unfortunately, the beta was delayed slightly, but it should be released in the coming days, likely early next week. I'll get back to you and send another message once it's out.

    Best Regards,
    John | Kreatura Dev Team

  •  77
    John replied

    Hi Zoran,

    The beta release is out now with the promised shortcode handling for image layers. Please let me know if you have questions or encounter any issues.

    Best Regards,
    John | Kreatura Dev Team