Categories
WordPress

Reolved failed upload in WordPress post edit filter

When adding an upload form to the post edit screen in WordPress admin, I found the upload to fail. The $_FILES array was empty.
The reason was that by default, WordPress post edit form does not send files data.

To fix that, we need to add enctype attribute to the form.
Here is the code to do that-

add_action( 'post_edit_form_tag' , 'post_edit_form_tag');
function post_edit_form_tag( ) {
    echo ' enctype="multipart/form-data"';
}

By Abhineet Mittal

Abhineet is IIM Alumnus and Founder of popular Digital Publishing Platform, Sahityapedia. He is a technology enthusiast by hobby & an avid reader.

Leave a Reply

Your email address will not be published. Required fields are marked *