Powered by Blogger.

Make post edit form support uploading file


In some cases, you need to upload a file attachment to the post/page but don’t want to use WordPress’ default Media upload. It can easily add

<input type="file" name="waytowp_upload_file_for_post" />


but may not get file data to move.

That means if you debug you will see $_FILES is empty. The problem is that, by default, the post edit form doesn’t accept file types. This can be fixed with WordPress’ hook post_edit_form_tag.

Just use the following codes:


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

No comments