I created a frontend form for upload images and worked fine.

The only problem is that I need generate attachment metadata for non images file. Now, metadata is only created for images files.

I'm using these lines for generate and insert metadata:

$attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
wp_update_attachment_metadata( $attachment_id, $attachment_data );


I made a verification to check if $attachment_data is empty (non-images files, like PDF):

    $fileMeta = array('file' => $imageUrl);
    add_post_meta($attachment_id, '_wp_attachment_metadata', $fileMeta);
    wp_update_attachment_metadata( $attachment_id, $attachment_data );  

1 Answer 1


wp_generate_metatadata() should create metadata for image, video, and audio file types. There is and if/elseif conditional in the source that limits the function to those three. However, the last line is:

return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );

So you could use the wp_generate_attachment_metadata filter to generate the metadata you want. There are plenty of answers here about creating filters, not to mention the Codex.

It is hard to say much more as you don't specify so much as what kind of "non-image" file you have.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.