When uploading files to WordPress, it’s not uncommon to encounter filenames that have been altered by various tools or processes. One of the main culprits is image optimization tools. These tools frequently append suffixes to the filenames to signify that they have been processed. For instance, an optimized image might have a suffix like “-optimized” or “-compressed”. Switching between optimization tools over time can clutter your media library with suffixes, making file management more confusing.
The following guide will walk you through a snippet that removes specific prefixes and suffixes from filenames during the upload process in WordPress, helping you maintain a clean naming convention.
How to Use the Snippet
Access Your Theme’s File:
Open your WordPress theme’s
php file. This can typically be accessed via FTP or through your hosting control panel.
Paste the Snippet:
At the end of the
functions.php file, paste the code snippet below.