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

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?

share|improve this question
up vote 3 down vote accepted

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)

share|improve this answer

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.