Title: wp media import
Published: February 5, 2018
Last modified: October 11, 2026

---

# 󠀁[wp media import ](https://developer.wordpress.org/cli/commands/media/import/)󠁿

Creates attachments from local files or URLs.

## In this article

 * [Options](https://developer.wordpress.org/cli/commands/media/import/?output_format=md#options)
 * [Examples](https://developer.wordpress.org/cli/commands/media/import/?output_format=md#examples)
 * [Global Parameters](https://developer.wordpress.org/cli/commands/media/import/?output_format=md#global-parameters)

[ Back to top](https://developer.wordpress.org/cli/commands/media/import/?output_format=md#wp--skip-link--target)

 [ ⌊GitHub⌉ ](https://github.com/wp-cli/media-command)

 [ View Open Issues (1) ](https://github.com/login?return_to=%2Fissues%3Fq%3Dlabel%3Acommand%3Amedia-import+sort%3Aupdated-desc+org%3Awp-cli+is%3Aopen)
[ View Closed Issues (43) ](https://github.com/login?return_to=%2Fissues%3Fq%3Dlabel%3Acommand%3Amedia-import+sort%3Aupdated-desc+org%3Awp-cli+is%3Aclosed)
[Create New Issue](https://github.com/wp-cli/media-command/issues/new)

>  **Note:** The following options are not part of a stable WP-CLI release yet: `--
> destination-dir`, `--skip-duplicates`. To use them now, [switch to the nightly build](https://make.wordpress.org/cli/handbook/guides/installing/#updating-wp-cli)
> with `wp cli update --nightly`. If you installed the command as a separate package,
> updating that package may be enough.

 Options added later: `--post_name` (2.8.0), `--file_name` (2.10.0).

### 󠀁[Options](https://developer.wordpress.org/cli/commands/media/import/?output_format=md#options)󠁿

 See the [argument syntax](https://make.wordpress.org/cli/handbook/references/argument-syntax/)
reference for a detailed explanation of the syntax conventions used.  <file>… Path
to file or files to be imported. Supports the glob(3) capabilities of the current
shell. If file is recognized as a URL (for example, with a scheme of http or ftp),
the file will be downloaded to a temp file before being sideloaded. Use ‘-‘ to read
file data from STDIN. [–post_id=<post_id>] ID of the post to attach the imported
files to. [–post_name=<post_name>] Name of the post to attach the imported files
to. [–file_name=<name>] Attachment name (post_name field). [–title=<title>] Attachment
title (post title field). [–caption=<caption>] Caption for attachment (post excerpt
field). [–alt=<alt_text>] Alt text for image (saved as post meta). [–desc=<description
>] “Description” field (post content) of attachment post. [–skip-copy] If set, media
files (local only) are imported to the library but not moved on disk. File names
will not be run through [wp_unique_filename()](https://developer.wordpress.org/reference/functions/wp_unique_filename/)
with this set. When used, files will remain at their current location and will not
be copied into any destination directory. [–destination-dir=<destination-dir>] Path
to the destination directory for uploaded imported files. Can be absolute or relative
to ABSPATH. Ignored when used together with –skip-copy, as files are not moved on
disk in that case. [–preserve-filetime] Use the file modified time as the post published&
modified dates. Remote files will always use the current time. [–featured_image]
If set, set the imported image as the Featured Image of the post it is attached 
to. [–skip-duplicates] If set, media files that have already been imported will 
be skipped. [–porcelain[=<field>]] Output a single field for each imported image.
Defaults to attachment ID when used as flag. — options: – url —

### 󠀁[Examples](https://developer.wordpress.org/cli/commands/media/import/?output_format=md#examples)󠁿

    ```
    # Import all jpgs in the current user's "Pictures" directory, not attached to any post.
    $ wp media import ~/Pictures/**\/*.jpg
    Imported file '/home/person/Pictures/landscape-photo.jpg' as attachment ID 1751.
    Imported file '/home/person/Pictures/fashion-icon.jpg' as attachment ID 1752.
    Success: Imported 2 of 2 items.

    # 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
    Imported file '/home/person/Downloads/image.png' as attachment ID 1753 and attached to post 123 as featured image.
    Success: Imported 1 of 1 images.

    # Import a local image, but set it as the featured image for all posts.
    # 1. Import the image and get its attachment ID.
    # 2. Assign the attachment ID as the featured image for all posts.
    $ ATTACHMENT_ID="$(wp media import ~/Downloads/image.png --porcelain)"
    $ wp post list --post_type=post --format=ids | xargs -d ' ' -I % wp post meta add % _thumbnail_id $ATTACHMENT_ID
    Success: Added custom field.
    Success: Added custom field.

    # Import an image from the web.
    $ wp media import https://s.w.org/style/images/wp-header-logo.png --title='The WordPress logo' --alt="Semantic personal publishing"
    Imported file 'https://s.w.org/style/images/wp-header-logo.png' as attachment ID 1755.
    Success: Imported 1 of 1 images.

    # Get the URL for an attachment after import.
    $ wp media import https://s.w.org/style/images/wp-header-logo.png --porcelain | xargs -I {} wp post list --post__in={} --field=url --post_type=attachment
    http://wordpress-develop.dev/wp-header-logo/

    # Import an image from STDIN.
    $ curl http://example.com/image.jpg | wp media import - --title="From STDIN"
    Imported file 'STDIN' as attachment ID 1756.
    Success: Imported 1 of 1 items.
    ```

### 󠀁[Global Parameters](https://developer.wordpress.org/cli/commands/media/import/?output_format=md#global-parameters)󠁿

 These [global parameters](https://make.wordpress.org/cli/handbook/config/) have
the same behavior across all commands and affect how WP-CLI interacts with WordPress.

  |  **Argument** |  **Description** |  
   |  `--path=<path>` |  Path to the WordPress files. |  
 |  `--url=<url>` |  Pretend request came from given URL. In multisite, this argument is how the target site is specified. |  
 |  `--ssh=[<scheme>:][<user>@]<host\|container>[:<port>][<path>]` |  Perform operation against a remote server over SSH (or a container using scheme of “docker”, “docker-compose”, “docker-compose-run”, “vagrant”). |  
 |  `--ssh-args=<args>` |  Pass additional arguments to SSH (or other tools specified by –ssh scheme). |  
 |  `--http=<http>` |  Perform operation against a remote WordPress installation over HTTP. |  
 |  `--user=<id\|login\|email>` |  Set the WordPress user. |  
 |  `--skip-plugins[=<plugins>]` |  Skip loading all plugins, or a comma-separated list of plugins. Note: mu-plugins are still loaded. |  
 |  `--skip-themes[=<themes>]` |  Skip loading all themes, or a comma-separated list of themes. |  
 |  `--skip-packages` |  Skip loading all installed packages. |  
 |  `--require=<path>` |  Load PHP file before running the command (may be used more than once). |  
 |  `--exec=<php-code>` |  Execute PHP code before running the command (may be used more than once). |  
 |  `--context=<context>` |  Load WordPress in a given context. |  
 |  `--[no-]color` |  Whether to colorize the output. |  
 |  `--debug[=<group>]` |  Show all PHP errors and add verbosity to WP-CLI output. Built-in groups include: bootstrap, commandfactory, and help. |  
 |  `--prompt[=<assoc>]` |  Prompt the user to enter values for all command arguments, or a subset specified as comma-separated values. |  
 |  `--quiet` |  Suppress informational messages. |  
 |  `--alias=<name>` |  Name of the alias to use. Aliases can reference local WordPress installations or remote SSH connections. Aliases are defined in the wp-cli.yml file. |  
 |  `--assume-https` |  Set $_SERVER[‘HTTPS’] to make WordPress treat the site as HTTPS. Use when WordPress is behind an HTTPS proxy or load balancer. |

 _Command documentation is regenerated at every release. To add or update an example,
please submit a pull request against the corresponding part of the codebase._