wp media fix-orientation
Fix images that display sideways or upside-down due to EXIF orientation metadata being ignored by browsers or WordPress. Physically rotates the image file to match its EXIF orientation tag, then clears the tag so it won't be double-applied.
The Problem This Solves
Photos taken on smartphones often have an orientation flag stored in EXIF metadata (e.g., "rotate 90°") rather than having the pixels physically rotated. Some browsers and image editors respect this flag; others ignore it. WordPress can also generate thumbnails without honouring it.
wp media fix-orientation reads the EXIF orientation of each image, applies the physical rotation, and removes the EXIF flag — so the image displays correctly everywhere.
Syntax
wp media fix-orientation [<attachment-id>...] [OPTIONS]
Options
| Flag | Description |
|---|---|
[ATTACHMENT_ID...] | One or more attachment IDs (default: all images) |
--dry-run | Show which images would be rotated without actually changing files |
--yes | Skip confirmation prompt |
Basic Usage
Fix orientation for all images
wp media fix-orientation --yes
Output:
1/87 Fixed orientation for "photo-landscape.jpg" (ID 101).
2/87 "product-shot.jpg" (ID 102) – already correct, skipping.
3/87 Fixed orientation for "team-selfie.jpg" (ID 103).
...
Success: Fixed orientation for 24 of 87 images.
Fix a single image by ID
wp media fix-orientation 101
Output:
1/1 Fixed orientation for "photo-landscape.jpg" (ID 101).
Success: Fixed orientation for 1 of 1 images.
Preview what would change (dry run)
wp media fix-orientation --dry-run
Output:
Would fix orientation for "photo-landscape.jpg" (ID 101).
Would fix orientation for "team-selfie.jpg" (ID 103).
2 images would be rotated.
Real-World Scenarios
Scenario 1: Post-import fix after bulk mobile photo upload
After importing photos taken on smartphones:
wp media import /var/www/uploads/phone-photos/*.jpg --yes
wp media fix-orientation --yes
Scenario 2: Fix specific known-bad IDs from a media audit
# List of IDs identified during QA
for id in 101 103 210 315; do
wp media fix-orientation "$id"
done
Scenario 3: Fix then regenerate thumbnails
After rotating the originals, regenerate all thumbnails so the derivatives are also correct:
wp media fix-orientation --yes
wp media regenerate --yes
Scenario 4: Scheduled check after weekly uploads
#!/bin/bash
# /opt/scripts/weekly-media-fix.sh
LAST_WEEK=$(date -d "7 days ago" +%Y-%m-%d)
RECENT_IDS=$(wp post list \
--post_type=attachment \
--after="$LAST_WEEK" \
--format=ids)
if [ -n "$RECENT_IDS" ]; then
wp media fix-orientation $RECENT_IDS
echo "Orientation fixed for recent uploads."
fi
Requirements
| Requirement | Details |
|---|---|
PHP exif extension | Must be enabled (php.ini: extension=exif) |
PHP imagick or gd | Used for the actual rotation |
| Original file writable | The original image file must be writable by PHP |
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
Warning: exif extension not loaded | PHP exif module not enabled | Enable in php.ini or install php-exif package |
Warning: No EXIF data found | Image has no EXIF orientation tag (already correct) | Normal — image is skipped |
| Image becomes blurry after fix | Re-compression on save | Use ImageMagick instead of GD (better quality preservation) |
| Permission denied | PHP cannot write the original file | Fix ownership: chown www-data:www-data /var/www/uploads/ |
Quick Reference
wp media fix-orientation --yes # Fix all
wp media fix-orientation <id> # Fix one
wp media fix-orientation --dry-run # Preview
wp media fix-orientation --yes && wp media regenerate --yes # Fix + regenerate
Next Steps
wp media regenerate— regenerate thumbnails after fixing orientation.wp media list— list media for finding affected attachment IDs.wp media import— import images before fixing orientation.