I would like to use an automated process to replicate a non-WordPress file folder in \wp-content\uploads\ and have the files automatically registered in the Media Library.

I could use such a process to upload the files, then register them using Add From Server (http://wordpress.org/plugins/add-from-server/) or the similar Media From FTP. But that seems like excessive human input.

LR/Blog (http://www.photographers-toolbox.com/products/lrblog.php) appears to be able to save to WP and register the files at the same time. How can this be done with any files using a command line?

1 Answer 1


I would suggest using WP CLI for that. It's the (in)official WordPress command line tool, like Drush for Drupal or the Symfony2 Console Component.

Use the media command to handle your (future) attachments:

wp media import <file> [--option=value*] 

* Take a look at the docs or the CLI help tool to see what options you got.

wp media import produces WordPress attachment post types from plain files, therefore letting them appear as uploads in the WP media library.

Examples from the docs.

# Import all jpgs in the current user's "Pictures" directory, not attached to any post
wp media import ~/Pictures/**\/*.jpg

# Import a local image and set it to be the post thumbnail for a post
wp media import ~/Downloads/image.png --post_id=123 --title="A downloaded picture" --featured_image

# Import an image from the web
wp media import http://s.wordpress.org/style/images/wp-header-logo.png --title='The WordPress logo' --alt="Semantic personal publishing"

(current state of code base while writing this question - later readers, read the docs on the official site)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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