Title: Finding orphan thumbnails
Last modified: January 28, 2021

---

# Finding orphan thumbnails

 *  [blazmate](https://wordpress.org/support/users/blazmate/)
 * (@blazmate)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/finding-orphan-thumbnails/)
 * Some plugins make thumbs and don’t register them.
 * So sometimes I have img.30×30.jpg left behind with no parent.
 * Is there a way to do an ls command, that looks at a dir and finds the image that
   only has something -???x??? without the full size one? Assume I never name things???
   x??

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/finding-orphan-thumbnails/#post-13980552)
 * Removing all files matching *.30×30.jpg would not delete any needed files?
    If
   the server is Linux and you have terminal access, `cd` to the right folder, then`
   rm *.30x30.jpg`
 * Files can be removed with custom PHP code. For example, place this in a new .
   php file and upload to /wp-content/:
 *     ```
       <?php // deletes all files matching uploads/2021/01/*.30x30.jpg
       array_map('unlink', glob("uploads/2021/01/*.30x30.jpg"));
       ```
   
 * I recommend backing up an entire folder before running code on it just in case
   more gets removed than you intend.
 *  Thread Starter [blazmate](https://wordpress.org/support/users/blazmate/)
 * (@blazmate)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/finding-orphan-thumbnails/#post-13981140)
 * No not all 30×30 files.
    You need to check like I said There are 6-7 sizes for
   each filename You can’t be sure what’s there
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/finding-orphan-thumbnails/#post-13982950)
 * Use `glob()` to get a list of all .jpg files in a directory. Search through the
   list with `preg_grep()` to find files like *-30×30.jpg. For each one found, see
   if there is a corresponding *.jpg full size file. If not found, unlink the current
   file and those similar. Use regular expressions to locate specific name formats
   and to capture the full size name portion. Regular expressions can be tricky 
   to define. Use a site like regexr.com to test out your regexp on various samples
   of file names.
 * If a lot of files exist in a directory, this can be pretty time consuming. Either
   adjust the regexp to limit how many files are processed at once, and/or extend
   the time allowed to execute PHP with something like `ini_set('max_execution_time',
   120); // default=30`
 *  Thread Starter [blazmate](https://wordpress.org/support/users/blazmate/)
 * (@blazmate)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/finding-orphan-thumbnails/#post-13983577)
 * this is going into php programming right?
    it’s a bit beyond me !
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/finding-orphan-thumbnails/#post-13987716)
 * Yeah, PHP coding. If that doesn’t work for you, maybe try one of the plugins 
   that regenerates images after the registered image sizes change. I somehow doubt
   they’ll flat out remove unneeded files though. Plugin authors are wary of writing
   code that deletes files without a very good reason. Or maybe there’s some sort
   of site cleanup plugin that will do what you need. It’s likely your search skills
   are as good as mine if not better. Sorry I can’t suggest anything more specific.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Finding orphan thumbnails’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [5 years, 4 months ago](https://wordpress.org/support/topic/finding-orphan-thumbnails/#post-13987716)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
