V
V
Vladislav2021-07-29 15:10:58
PHP
Vladislav, 2021-07-29 15:10:58

How to do Preview image before upload on Wordpress site?

There is a form in the frontend, through which users upload information for a post to the site. In this form, you can also upload an image as the cover of the publication. However, the form does not display a preview of the uploaded image. Only specifies a link to an image on the server.
How can I implement a preview of an image before sending it to the server?

The code responsible for attaching the image:

if( get_option('show_feature') == 'true' ){
            $html .= '<div class="new-single">';
            $html .= '<div class="new-name">'.__( "Feature Image" , "new-operator" ).'</div>';
            $html .= '<div class="new-fields">';
            $html .= '<input type="text" readonly="readonly" name="new-form-image-url" class="new-upload new-form-image-url" value="'.$image_url.'">';
            $html .= '<input type="hidden" name="new-form-image-id" class="new-form-image-id" value="'.$image_id.'">';
            $html .= '<input type="button" id="image-upload-file-button" class="new-image-upload float-right" value="'.__("Upload Image","new-operator").'" data-url="'. get_site_url().'" />';
            $html .= '</div>';
            $html .= '</div>';
            }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question