wp media <command>

Imports files as attachments, regenerates thumbnails, replaces existing attachment files, or lists registered image sizes.

In this article

Examples

# Re-generate all thumbnails, without confirmation.
$ wp media regenerate --yes
Found 3 images to regenerate.
1/3 Regenerated thumbnails for "Sydney Harbor Bridge" (ID 760).
2/3 Regenerated thumbnails for "Boardwalk" (ID 757).
3/3 Regenerated thumbnails for "Sunburst Over River" (ID 756).
Success: Regenerated 3 of 3 images.

# Import a local image and set it to be the featured image 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 an image from STDIN.
$ curl http://example.com/image.jpg | wp media import -
Imported file 'STDIN' as attachment ID 1754.
Success: Imported 1 of 1 items.

# List all registered image sizes
$ wp media image-size
+---------------------------+-------+--------+-------+
| name                      | width | height | crop  |
+---------------------------+-------+--------+-------+
| full                      |       |        | N/A   |
| twentyfourteen-full-width | 1038  | 576    | hard  |
| large                     | 1024  | 1024   | soft  |
| medium_large              | 768   | 0      | soft  |
| medium                    | 300   | 300    | soft  |
| thumbnail                 | 150   | 150    | hard  |
+---------------------------+-------+--------+-------+

# Fix orientation for specific images.
$ wp media fix-orientation 63
1/1 Fixing orientation for "Portrait_6" (ID 63).
Success: Fixed 1 of 1 images.

# Remove all generated thumbnails, without confirmation.
$ wp media prune --yes
Found 3 images to prune.
1/3 Pruned thumbnails for "Sydney Harbor Bridge" (ID 760).
2/3 Pruned thumbnails for "Boardwalk" (ID 757).
3/3 Pruned thumbnails for "Sunburst Over River" (ID 756).
Success: Pruned 3 of 3 images.

Subcommands

NameDescription
wp media fix-orientation

Fix image orientation for one or more attachments.

wp media image-size

Lists image sizes registered with WordPress.

wp media import

Creates attachments from local files or URLs.

wp media prune

Removes all generated image files for one or more attachments.

wp media regenerate

Regenerates thumbnails for one or more attachments.

wp media replace

Replaces the file for an existing attachment while preserving its identity.

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.