Featured Image Migration Tool
WordPress plugin that migrates manually added first content images to proper featured image display, eliminating duplicate image processing and improving performance.
by Chris Huber · github.com/chubes4/featured-image-migration · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/chubes4/featured-image-migration/archive/refs/heads/main.zipReadme
Featured Image Migration Tool
A WordPress plugin that automatically migrates manually added first content images to proper featured image display, eliminating duplicate image processing and improving site performance.
Problem Solved
Many WordPress users set a featured image AND manually add the same image to their post content, creating:
- Duplicate image display (when themes show both)
- SEO issues with duplicate images in sitemaps
- Cluttered content structure
- Poor editorial workflow
This plugin automatically removes the first content image block when it matches the featured image, streamlining your content while preserving the featured image for SEO and social media purposes.
Features
- Automated Migration: Converts manually added first images to featured image display
- Performance Optimization: Eliminates duplicate image processing and improves page load times
- Batch Processing: AJAX-powered migration with real-time progress tracking
- Security First: Comprehensive nonces, capability checks, and input sanitization
- Gutenberg Integration: Advanced block parsing to safely identify and remove image blocks
- Multi-Post-Type Support: Works with 'post' and 'recipe' post types
- Smart Detection: Only migrates when first content image matches the featured image
- Detailed Logging: Real-time migration progress with detailed success/skip reporting
Requirements
- WordPress: 5.0 or higher
- PHP: 7.4 or higher
- Block Editor: Gutenberg block editor (Classic Editor not supported)
- User Permissions: Administrator role required for migration operations
Installation
Manual Installation
- Download the plugin files
- Upload
featured-image-migration.phpto/wp-content/plugins/featured-image-migration/ - Activate the plugin through the 'Plugins' menu in WordPress
- Navigate to any admin page to see the migration notice
WordPress Repository (Future)
This plugin is designed for WordPress repository standards and can be packaged for distribution.
Usage
Running the Migration
- Activate the Plugin: The migration notice appears automatically for administrators
- Review Posts: Click "Migrate All Images" to start the process
- Monitor Progress: Watch real-time progress with detailed logging
- Complete Migration: Process completes automatically with summary statistics
Migration Process
The plugin performs these steps for each post:
- Validates Post: Checks for published status and featured image presence
- Parses Blocks: Analyzes Gutenberg block structure for image blocks
- Matches Images: Compares first content image with featured image
- Removes Duplicate: Safely removes first image block if it matches featured image
- Updates Content: Saves modified content while preserving all other blocks
What Gets Migrated
- ✅ Posts with featured images set
- ✅ Posts containing Gutenberg image blocks
- ✅ First image block matches featured image ID
- ✅ Published posts only
What Gets Skipped
- ❌ Posts without featured images
- ❌ Posts without image blocks
- ❌ Posts where first image doesn't match featured image
- ❌ Draft or private posts
- ❌ Classic Editor content
Technical Details
Supported Post Types
post- Standard WordPress postsrecipe- Recipe post type (if available)
Block Processing
The plugin uses WordPress core functions for safe block manipulation:
parse_blocks()- Parses post content into block structureserialize_blocks()- Converts blocks back to content- Recursive traversal for nested blocks (columns, groups, etc.)
- Safe array manipulation with proper re-indexing
Security Features
- Nonce Verification: All AJAX requests protected with WordPress nonces
- Capability Checks: Requires
manage_optionscapability - Input Sanitization: All user inputs properly sanitized
- Error Handling: Comprehensive error reporting and recovery
Performance Optimization
- Batch Processing: Configurable batch sizes (default: 20 posts)
- Memory Management: Efficient processing prevents server overload
- Progress Throttling: 500ms delays between batches
- Selective Processing: Only processes relevant posts
Development
File Structure
featured-image-migration/
├── featured-image-migration.php # Main plugin file (466 lines)
├── CLAUDE.md # AI development context
└── README.md # This documentation
Key Functions
migrate_post_image($post_id)- Core migration logicfind_first_image_block($blocks)- Recursive block finderremove_first_image_block($blocks)- Safe block removalcount_migration_posts()- AJAX post countermigrate_images_batch()- AJAX batch processor
WordPress Standards
- PSR-4 autoloading ready
- WordPress Coding Standards compliant
- Internationalization support (
featured-image-migrationtext domain) - Proper plugin header with all metadata
Migration Statistics
After migration completion, you'll see:
- Total Posts Processed: Number of posts examined
- Successfully Migrated: Posts with duplicate images removed
- Skipped Posts: Posts that didn't meet migration criteria
- Detailed Log: Real-time processing information
Troubleshooting
Common Issues
Migration Notice Doesn't Appear
- Ensure user has Administrator role
- Check that posts have featured images set
- Verify WordPress is using Gutenberg editor
No Posts Being Migrated
- Confirm posts contain image blocks in content
- Verify first image matches featured image
- Check posts are published (not draft/private)
Migration Stops or Fails
- Check server error logs for PHP errors
- Ensure adequate server memory and execution time
- Verify WordPress and PHP version requirements
Debug Information
Enable WordPress debug logging to troubleshoot issues:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
Contributing
Development Setup
- Clone or download the plugin
- Place in WordPress plugins directory
- Activate in WordPress admin
- Test with posts containing featured images and image blocks
Code Standards
- Follow WordPress Coding Standards
- Use WordPress core functions for all operations
- Maintain security-first approach
- Document all public methods
- Test with various block structures
Security Guidelines
- Always verify nonces for AJAX requests
- Check user capabilities before operations
- Sanitize all user inputs
- Use WordPress post update functions
- Handle errors gracefully
License
GPL v2 or later - https://www.gnu.org/licenses/gpl-2.0.html
Author
Chris Huber
- Website: chubes.net
- GitHub: @chubes4
Support
For issues or questions:
- Check the troubleshooting section above
- Review WordPress error logs
- Ensure requirements are met
- Test with minimal plugin configuration
This plugin is designed to be a one-time migration tool. Once migration is complete, the plugin can be safely deactivated and removed if no longer needed.