Skip to main content

wp media fix-orientation

Overview

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

FlagDescription
[ATTACHMENT_ID...]One or more attachment IDs (default: all images)
--dry-runShow which images would be rotated without actually changing files
--yesSkip 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

RequirementDetails
PHP exif extensionMust be enabled (php.ini: extension=exif)
PHP imagick or gdUsed for the actual rotation
Original file writableThe original image file must be writable by PHP

Troubleshooting

ProblemCauseFix
Warning: exif extension not loadedPHP exif module not enabledEnable in php.ini or install php-exif package
Warning: No EXIF data foundImage has no EXIF orientation tag (already correct)Normal — image is skipped
Image becomes blurry after fixRe-compression on saveUse ImageMagick instead of GD (better quality preservation)
Permission deniedPHP cannot write the original fileFix 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