Introduction
Fixing generic image filenames in WordPress for law firm websites matters because names like `IMG_4821.jpg` or `stock-photo-7.png` waste a strong relevance signal for practice-area pages, attorney bios, and location content. In a 2026 WordPress stack, the goal is not just prettier filenames. You want image URLs, attachment metadata, and page context to line up with the queries potential clients actually use, such as personal injury lawyer, estate planning attorney, or divorce mediation in a target city.
For law firms, this work has a higher stakes SEO angle than it does for many generic business sites. Practice pages often compete locally, image assets get reused across service templates, and old media URLs may already be indexed or embedded in schema, Open Graph tags, and internal content blocks. A careless rename can break image references and create crawl waste. A controlled workflow lets you replace weak filenames with descriptive, compliant names while preserving rankings and avoiding media-library damage.
Prerequisites
This process works because WordPress stores filenames in multiple places, so you need the right tools before changing anything.
- WordPress 6.7 or 6.8
- PHP 8.2 or 8.3
- MySQL 8.0 or MariaDB 10.6+
- WP-CLI 2.10+
- Ubuntu 24.04 LTS or Debian 12 on the web server
- Nginx 1.24+ or Apache 2.4+
- SSH access as a non-root deployment user
- Full file backup of `wp-content/uploads/`
- Database backup before bulk updates
- Yoast SEO or a comparable SEO plugin if attachment metadata is already managed
| Component | Recommended Version | Why It Matters |
|---|---|---|
| WordPress | 6.7 or 6.8 | Stable media handling and current block editor behavior |
| PHP | 8.3 | Common 2026 production target for WordPress hosts |
| WP-CLI | 2.10+ | Safer search-replace and media inspection commands |
| Server OS | Ubuntu 24.04 | Predictable package names and CLI tooling |
Installation And Setup
A safe setup prevents broken image URLs, which is critical when attorney profile photos and trust-building office images are already live.
Start by moving into the WordPress document root as your normal deploy user, not root.
cd /var/www/lawfirm-site/current
wp core version
wp cli version
php -v
Expected output will look similar to this.
6.8
WP-CLI 2.10.0
PHP 8.3.6 (cli)
Back up uploads and the database before you touch filenames.
mkdir -p /var/backups/lawfirm-media
rsync -a wp-content/uploads/ /var/backups/lawfirm-media/uploads-pre-rename/
wp db export /var/backups/lawfirm-media/pre-rename.sql
If you need a current view of media usage, export attachment records first.
wp db query "
SELECT ID, post_title, guid
FROM wp_posts
WHERE post_type = 'attachment'
ORDER BY ID DESC
LIMIT 25;
"
For image-heavy firms, I also recommend reviewing related performance and media guidance before changing assets:
- Web Image Performance In 2026
- Installing Imagick For PHP 8.3 On Ubuntu 24
- 9 Free WordPress Media Optimization Plugins Compared
Configuration
The right configuration defines how filenames should look and why, so legal content stays descriptive without creating thin or spammy media URLs.
For law firm websites, use a naming pattern tied to the page intent, not the camera export. A good format is:
practice-area-city-descriptor.webp
Examples:
- `personal-injury-lawyer-chicago-courtroom.webp`
- `estate-planning-attorney-phoenix-consultation-room.jpg`
- `family-law-firm-austin-lead-counsel-headshot.png`
Use these rules when deciding final names.
- Include the practice area or attorney topic when relevant.
- Add the city only when the page is location-targeted.
- Keep names short, human-readable, and lowercase.
- Use hyphens, not underscores.
- Do not stuff multiple keyword variants into one filename.
- Avoid dates unless the image is tied to an event or year-specific report.
- Keep confidential client names out of filenames.
Before bulk changes, find generic patterns already in the library.
wp db query "
SELECT ID, guid
FROM wp_posts
WHERE post_type = 'attachment'
AND (
guid REGEXP 'IMG_[0-9]+'
OR guid REGEXP 'DSC[0-9]+'
OR guid LIKE '%stock-photo%'
OR guid LIKE '%screenshot%'
)
LIMIT 100;
"
If you use Nginx and old image URLs may still receive traffic from Google Images or external links, prepare a redirect map. Store it outside the public uploads folder.
sudo mkdir -p /etc/nginx/redirect-maps
sudo touch /etc/nginx/redirect-maps/lawfirm-images.map
A sample map entry looks like this.
/map/wp-content/uploads/2025/11/IMG_4821.jpg /wp-content/uploads/2025/11/personal-injury-lawyer-chicago-courtroom.jpg;
For Apache, use targeted 301 rules instead of a broad media rewrite.
Redirect 301 /wp-content/uploads/2025/11/IMG_4821.jpg /wp-content/uploads/2025/11/personal-injury-lawyer-chicago-courtroom.jpg
Usage And Execution
Execution means renaming the physical file, updating WordPress references, and verifying that page-level image usage still works.
The safest approach for law firm sites is batch-by-batch, usually one practice area or one attorney section at a time. First inspect an attachment and locate the actual file path.
wp post meta get 1842 _wp_attached_file
wp eval 'print_r( wp_get_attachment_metadata(1842) );'
Typical output:
2025/11/IMG_4821.jpg
Array
(
[width] => 1600
[height] => 900
[file] => 2025/11/IMG_4821.jpg
[sizes] => Array
(
[medium] => Array
(
[file] => IMG_4821-300x169.jpg
)
)
)
Rename the original file and any generated size variants together. If you only rename the main file, WordPress metadata becomes inconsistent.
cd /var/www/lawfirm-site/current/wp-content/uploads/2025/11
mv IMG_4821.jpg personal-injury-lawyer-chicago-courtroom.jpg
mv IMG_4821-300x169.jpg personal-injury-lawyer-chicago-courtroom-300x169.jpg
mv IMG_4821-768x432.jpg personal-injury-lawyer-chicago-courtroom-768x432.jpg
Then update attachment metadata and GUID-related content references carefully. Do not do a blind database-wide replacement until you confirm scope.
wp search-replace '2025/11/IMG_4821.jpg' '2025/11/personal-injury-lawyer-chicago-courtroom.jpg' --include-columns=post_content,guid,meta_value --precise --report-changed-only
wp search-replace 'IMG_4821-300x169.jpg' 'personal-injury-lawyer-chicago-courtroom-300x169.jpg' --include-columns=post_content,meta_value --precise --report-changed-only
wp search-replace 'IMG_4821-768x432.jpg' 'personal-injury-lawyer-chicago-courtroom-768x432.jpg' --include-columns=post_content,meta_value --precise --report-changed-only
Update the attachment title and alt text if they are also generic. This is usually worth doing on law firm sites because many media libraries were populated from stock shoots or staff uploads.
wp post update 1842 --post_title='Personal Injury Lawyer In Chicago Courtroom'
wp post meta update 1842 _wp_attachment_image_alt 'Chicago personal injury lawyer in courtroom'
If many images were uploaded with poor names but correct visual intent, create a rename worksheet first. A simple CSV structure works well.
| Attachment ID | Old Filename | New Filename | Page Context |
|---|---|---|---|
| 1842 | IMG_4821.jpg | personal-injury-lawyer-chicago-courtroom.jpg | Personal injury service page |
| 1910 | stock-photo-7.png | estate-planning-attorney-phoenix-consultation-room.png | Estate planning landing page |
| 2054 | DSC8821.jpg | family-law-firm-austin-lead-counsel-headshot.jpg | Attorney bio page |
After each batch, regenerate affected metadata if needed.
wp media regenerate 1842 1910 2054 --yes
Then verify the updated pages in the browser and in the rendered HTML. You are checking that the image URL, alt text, and structured context still align.
wp post get 1842 --field=guid
wp db query "SELECT post_id, meta_key FROM wp_postmeta WHERE post_id = 1842 AND meta_key LIKE '%_wp_%';"
For SEO-side validation, compare your filename work with broader plugin and content strategy resources:
- Best WordPress SEO Plugins For Agencies In 2026
- Best WordPress Image Alt Text Generator Plugins For Agencies In 2026
Troubleshooting
Troubleshooting matters because most filename migrations fail from metadata mismatches, stale caches, or overlooked embeds rather than from the rename itself.
Attachment Still Points To The Old Filename
This happens when the file moved but `_wp_attached_file` or serialized metadata still references the old path.
Check the stored values.
wp post meta get 1842 _wp_attached_file
wp eval 'print_r( wp_get_attachment_metadata(1842) );'
If the old value remains, rerun targeted replacements and regenerate metadata.
wp search-replace 'IMG_4821' 'personal-injury-lawyer-chicago-courtroom' --include-columns=meta_value --precise --report-changed-only
wp media regenerate 1842 --yes
Images Break On Practice Pages After Rename
This usually means the page builder or block content stored an absolute media URL that was not updated.
Search content references directly.
wp db query "
SELECT ID, post_title
FROM wp_posts
WHERE post_content LIKE '%IMG_4821%';
"
If results appear, run a content-only replacement and clear caches at the edge and plugin level.
wp search-replace 'IMG_4821.jpg' 'personal-injury-lawyer-chicago-courtroom.jpg' --include-columns=post_content --precise --report-changed-only
CDN Or Cache Still Serves The Old Image URL
This is common when Cloudflare, Bunny, or a host-level cache has the old asset cached even after WordPress is fixed.
Check headers with `curl`.
curl -I https://examplelawfirm.com/wp-content/uploads/2025/11/personal-injury-lawyer-chicago-courtroom.jpg
curl -I https://examplelawfirm.com/wp-content/uploads/2025/11/IMG_4821.jpg
Desired result:
- New URL returns `200 OK`
- Old URL returns `301 Moved Permanently` to the new URL, or `404` only if the asset had no SEO value and no inbound references
For indexed legal-service images, prefer a 301 over a hard drop.
Conclusion
Fixing generic image filenames in WordPress for law firm websites is a technical cleanup with real SEO upside when done carefully. The win is not the filename alone. The win comes from aligning media URLs, alt text, attachment metadata, and page intent around the services and locations that drive qualified leads. For legal sites, that usually means better topical clarity on service pages, cleaner image search signals, and fewer weak assets lingering in the index.
The safest path in 2026 is a controlled batch workflow: inventory generic names, map each asset to a page purpose, rename the files, update WordPress references, regenerate metadata, and verify redirects and cache behavior. If you treat the media library like production infrastructure instead of a cosmetic library cleanup, you can improve relevance without introducing broken pages or crawl noise.