wp media
Imports files as attachments, regenerates thumbnails, or lists registered image sizes.
Subcommands
| Command | Description |
|---|---|
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 regenerate |
Regenerates thumbnails for one or more attachments. |
wp media fix-orientation
Fix image orientation for one or more attachments.
Synopsis
wp media fix-orientation [<attachment-id>...] [--dry-run]
Options
[<attachment-id>...]
: One or more IDs of the attachments to regenerate.
[--dry-run]
: Check images needing orientation without performing the operation.
Examples
# Fix orientation for all images.
$ wp media fix-orientation
1/3 Fixing orientation for "Landscape_4" (ID 62).
2/3 Fixing orientation for "Landscape_3" (ID 61).
3/3 Fixing orientation for "Landscape_2" (ID 60).
Success: Fixed 3 of 3 images.
# Fix orientation dry run.
$ wp media fix-orientation 63 --dry-run
1/1 "Portrait_6" (ID 63) will be affected.
Success: 1 of 1 image will be affected.
# 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.
wp media image-size
Lists image sizes registered with WordPress.
Synopsis
wp media image-size [--fields=<fields>] [--format=<format>]
Options
[--fields=<fields>]
: Limit the output to specific fields. Defaults to all fields.
[--format=<format>]
: Render output in a specific format.
- default: table
- options: table, json, csv, yaml, count
Available Fields
- name
- width
- height
- crop
- ratio
Examples
$ wp media image-size
+---------------------------+-------+--------+-------+-------+
| name | width | height | crop | ratio |
+---------------------------+-------+--------+-------+-------+
| full | | | N/A | N/A |
| twentyfourteen-full-width | 1038 | 576 | hard | 173:96|
| large | 1024 | 1024 | soft | N/A |
| medium_large | 768 | 0 | soft | N/A |
| medium | 300 | 300 | soft | N/A |
| thumbnail | 150 | 150 | hard | 1:1 |
+---------------------------+-------+--------+-------+-------+
wp media import
Creates attachments from local files or URLs.
Synopsis
wp media import <file>... [--post_id=<post_id>] [--post_name=<post_name>] [--file_name=<name>] [--title=<title>] [--caption=<caption>] [--alt=<alt_text>] [--desc=<description>] [--skip-copy] [--preserve-filetime] [--featured_image] [--porcelain[=<field>]]
Options
<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.
[--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.
[--preserve-filetime]
: Use the file modified time as the post published & modified dates.
[--featured_image]
: If set, set the imported image as the Featured Image of the post it is attached to.
[--porcelain[=<field>]]
: Output a single field for each imported image. Defaults to attachment ID when used as flag.
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 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"
Imported file 'http://s.wordpress.org/style/images/wp-header-logo.png' as attachment ID 1755.
Success: Imported 1 of 1 images.
wp media regenerate
Regenerates thumbnails for one or more attachments.
Synopsis
wp media regenerate [<attachment-id>...] [--image_size=<image_size>] [--skip-delete] [--only-missing] [--delete-unknown] [--yes]
Options
[<attachment-id>...]
: One or more IDs of the attachments to regenerate.
[--image_size=<image_size>]
: Name of the image size to regenerate. Only thumbnails of this image size will be regenerated.
[--skip-delete]
: Skip deletion of the original thumbnails.
[--only-missing]
: Only generate thumbnails for images missing image sizes.
[--delete-unknown]
: Only delete thumbnails for old unregistered image sizes.
[--yes]
: Answer yes to the confirmation message.
Examples
# Regenerate thumbnails for given attachment IDs.
$ wp media regenerate 123 124 125
Found 3 images to regenerate.
1/3 Regenerated thumbnails for "Vertical Image" (ID 123).
2/3 Regenerated thumbnails for "Horizontal Image" (ID 124).
3/3 Regenerated thumbnails for "Beautiful Picture" (ID 125).
Success: Regenerated 3 of 3 images.
# Regenerate 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.
# Re-generate only the thumbnails of "large" image size for all images.
$ wp media regenerate --image_size=large
Do you really want to regenerate the "large" image size for all images? [y/n] y
Found 3 images to regenerate.
1/3 Regenerated "large" thumbnail for "Sydney Harbor Bridge" (ID 760).
2/3 No "large" thumbnail regeneration needed for "Boardwalk" (ID 757).
3/3 Regenerated "large" thumbnail for "Sunburst Over River" (ID 756).
Success: Regenerated 3 of 3 images.