How to list all images on your WordPress website
Managing images on a WordPress website is crucial for maintaining an organized, efficient, and high-performing site. Whether you’re looking to audit your content, review external photos and licenses, prepare for a redesign, analyze image usage, or ensure proper backups, having a comprehensive list of all images on your site can be incredibly beneficial. This article will explore various solutions to list all images on a WordPress site, catering to a wide range of technical abilities. I’ll cover everything from built-in WordPress features to advanced command-line tools.
Why list all images on your website?
Content Audit and Optimization
A content audit helps identify which images actively contribute to your website’s content and which are just taking up space. This process can improve your site’s SEO and page load speed by removing unused images, compressing large files, and ensuring all images have proper alt text.
Website Redesign
When redesigning your website, having a list of all images ensures you are not missing any visual elements. This is particularly important if you’re changing themes or layouts, as it helps you plan where and how to use each image in the new design.
Reviewing image licenses
Many users of Image Source Control face the challenge of going through their whole website after a long time and checking the license of used images. It helps them tremendously that Image Source Control can determine if an image is used and show which post it is on.
They can also enter the author attributions in the plugin, which makes it easy to list all images with unclear licensing.
1. Using the WordPress Media Library
- Access the Media Library: Log in to your WordPress dashboard and navigate to Media > Library.
- Use Filters and Sorting Options: To organize your view, use the filters (All Media Items, Images, Audio, Video) and sorting options (Date, Media Type).
- List Images: Scroll through the library to view all images. To navigate more easily, switch between List and Grid views. I personally prefer the first.
Pros and Cons
- Pros: Easy to use, no additional plugins or tools required.
- Cons: Does not distinguish between used and unused images; limited sorting and filtering options. For more information on the “Attached” state, see Delete Unattached Media in WordPress.
2. List all images with a WordPress Plugin
With the WordPress plugin Image Source Control, you can find all images on a website for various use cases:
- Identify unused images to clean up your site
- List images under various conditions in the Global List on the frontend:
- all images in the Media Library
- all images with author attributions
- all images actively used in the frontend
- List images and the posts using them in a dedicated list in the backend.
Get Image Source Control to follow the instructions for each use case below.
Find unused images
Once you install Image Source Control, you will find the list of all unused images under Media > Unused Images.
From here, you can run an additional deep check to confirm that the image isn’t used in any option or meta information before safely removing it. You can also run the check and deletion in bulk.
For more details, see Delete Unused Images.
Using the Global List
The Global List feature in Image Source Control is the answer to how to see all images on a website in the frontend of your WordPress site.
I usually place this list on a dedicated page on my website, linking it directly in the footer menu or on the imprint page.
Occasionally, I use it to check which images are used where and whether some are missing author attributions.
You can choose which images are listed here:
- List all images in your WordPress Media Library.
- List images actively used in the content of posts and pages.
- List images with author attributions.
You can also customize the columns by turning them on and off:
- Thumbnail
- Attachment ID
- Image Title
- Posts in which the image appears
- Author Attribution
Listing Image-Post relations
Finally, the Tools page of Image Source Control under Media > Image Sources offers various options for listing all images on your WordPress site.
The List post-image relations button opens a list of posts with all images in them.
The List image-post relations button shows the posts to which each individual image is related.
I have received some requests to extend both lists on a dedicated page in the backend. Let me know if that is also of interest to you.
3: Using FTP/SFTP
Another way to list all WordPress images is to check your server. This is usually done via (S)FTP.
You can find all the images under wp-content/uploads
. By default, they are ordered by the year and month in which they were uploaded, e.g., wp-content/uploads/2024/7
.
You can disable these time-based subfolders for future uploads under Settings > Media > Uploading Files. Only without that option enabled would you find a complete list of all images in a single folder. Otherwise, if you looked for one, you would need to know the upload date. I regretted more than once that I hadn’t turned off the option when starting a project.
Here is how to get to your server:
- Access FTP/SFTP: Use an FTP client like FileZilla to connect to your website’s server. You’ll need your FTP credentials (host, username, password).
- Navigate to Uploads Directory: Once connected, navigate to
wp-content/uploads
. - List Image Files: Browse through the folders to see all image files.
As you will see now, many images have multiple files. Most of them will contain the image size in their file name.
Ideally, these are all the files in your Media Library, though a corrupt upload or broken backup could add images that are (no longer) in your Media Library.
Pros and Cons
- Pros: Provides a raw list of images; no need for additional plugins.
- Cons: Requires technical knowledge; does not tell if an image is still in the Media Library or even used.
4: Custom PHP Script
I rarely write custom PHP to accomplish tasks now if a simple plugin can fulfill the requirement quickly and save me time.
But if you want to build your own solution, here is a starting point to list all images from the uploads
directory.
<?php
function list_all_images() {
$upload_dir = wp_upload_dir();
$base_dir = $upload_dir['basedir'];
// Function to recursively list images in a directory
function get_images($dir) {
$images = [];
$files = scandir($dir);
foreach ($files as $file) {
if ($file != '.' && $file != '..') {
$path = $dir . '/' . $file;
if (is_dir($path)) {
$images = array_merge($images, get_images($path));
} else {
if (preg_match('/\.(jpg|jpeg|png|gif)$/i', $file)) {
$images[] = $path;
}
}
}
}
return $images;
}
// Get all images
$all_images = get_images($base_dir);
// Output images
foreach ($all_images as $image) {
echo $image . "<br>";
}
}
add_shortcode('list_all_images', 'list_all_images');
Code language: HTML, XML (xml)
Running the Script
- Add the Script to functions.php or a custom plugin.
- Use the Shortcode: Add the shortcode
[list_all_images]
to a page or post to display the list of images.
Pros and Cons
- Pros: Highly customizable; can tailor the script to specific needs.
- Cons: Requires coding skills; potential security risks if not handled properly.
Conclusion
Listing all images on your WordPress website can be straightforward or complex, depending on the method you choose and your technical proficiency.
There are multiple ways to achieve this goal, from the built-in media library to a dedicated plugin. Regularly auditing and managing your images not only helps maintain an organized site but also improves performance and user experience. Choose the method that best fits your needs and technical comfort level, and keep your media library review efficient.
PS: I intentionally left out external tools here, but you might want to know that some site scrapers check all images. Their advantage is that they only find actively used images, but they don’t have that deep WordPress integration I focussed on in this tutorial.
FAQ
Install Image Source Control to see all images on your WordPress website. You can either access the various index tools in the backend or create a dedicated page to show the Global List.
Questions? Feedback? How can I help?
Reach out directly via the contact form.