Ideally what I'd like to do is hand a file to a function that returns the file as an attachment of the current post. Just as though it had been uploaded via the thickbox media uploader, but without the hassle of hijacking it's ugly interface.

Is there a plugin/library/function I can use with my own plugins to achieve this?

1 Answer 1


You can do that programatically via wp_insert_attachment() function.

Here is an example at WP Codex: http://codex.wordpress.org/Function_Reference/wp_insert_attachment

  • Right, so does this trigger the rest of the stuff (moving the image to the uploads folder, resizing, generating thumbnails, etc)? I can't tell from the codex page.
    – Tom
    Jul 4, 2011 at 13:36

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.