WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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

share|improve this answer
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 '11 at 13:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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