• Resolved Sabbir Hasan

    (@shshouvo)


    I’m trying to show static image preview as dynamic preview. what I’v tried so far

    firstly remove action thats rendering dynamic preview.
    remove_action('acfe/flexible/preview', 'acfe_flexible_layout_preview_render',100,2);

    then i’m trying to load a static image

    add_action('acfe/flexible/preview', 'acf_flexible_preview', 100, 2);
    function acf_flexible_preview($field, $layout){
        echo '<img src="my-image-png"/>';
    }

    Issue is the remove_action part not working. It’s not being removed.

Viewing 1 replies (of 1 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback. The ACF Extended action is on the priorty 99, not 100. Also note that you don’t have to set the number of arguments when using remove_action().

    See the documentation: https://developer.ww.wp.xz.cn/reference/functions/remove_action/

    If you want to remove the action, you should be doing:

    remove_action('acfe/flexible/preview', 'acfe_flexible_layout_preview_render', 99);

    But I would not recommend doing that, as the function name could change in the future. There is a tutorial that explain how to display an image in the preview mode, directly in the layout template. See https://www.acf-extended.com/post/flexible-content-dynamic-layout-preview

    Here is the code to put in your layout template file:

    
    <?php 
    
    /** 
     * Layout Render Template.
     * 
     * @array   $layout     Layout settings (without values) 
     * @array   $field      Flexible content field settings 
     * @bool    $is_preview True during AJAX preview 
     */
    
    // Preview Render
    if($is_preview){
        
        if(acf_maybe_get($layout, 'acfe_flexible_thumbnail')){
            
            $thumbnail_src = wp_get_attachment_url($layout['acfe_flexible_thumbnail']);
            
            echo '<img src="' . $thumbnail_src . '" style="max-width:100%; height:auto;" />';
            
        }
    // Front-End Render
    }else{
        
        // ...
        
    }
    

    Regards.

Viewing 1 replies (of 1 total)

The topic ‘Dynamic Preview show static image preview’ is closed to new replies.