5 ways to find out where an image is used on a WordPress site
As a WordPress site owner or manager, you may occasionally need to locate whether or where specific images are being used on your site. This tutorial will provide you with various options on how to find the exact locations of your images on your WordPress site.
There are several situations in which I personally need to find where an image is used:
- Remove orphaned images: Unused images take up space. Not just server space – especially since WordPress stores the same image in multiple sizes – but also space in the media library. I like to keep my media library clean to find pictures from the past faster. See How to find unused images in WordPress.
- Replace outdated images: Sometimes, a new version of Image Source Control contains updated strings or new elements in the interface. In these cases, there are always one or two screenshots in the manual that need updating. I am using some screenshots in multiple places, so I need a way to identify these.
- Improve existing images / SEO: Sometimes, I like to update certain image descriptions or alt texts for SEO purposes or check if the caption entered in the media library is really displayed. I could go through each post manually or work on specific images or image types in bulk, for which I would need to find them.
In this tutorial, I will discuss various methods to find where an image is used on a WordPress site. I have tried all of them and will highlight my preferred choice in the final conclusion.
Tested methods:
- “Uploaded to” information in the Media Library
- Using Image Source Control
- Search the database directly
- Post Search in the Backend
- Google Images reverse search
Find used Images in the WordPress Media Library
When you upload an image directly to a page or post using the block or classic editor, WordPress automatically associates the image with that specific content. The “Uploaded to” section of the image details in the Media Library displays the title of that associated page or post, along with a clickable link that takes you directly to the edit screen.
If an image has not been attached to any content, the “Uploaded to” section will display “Unattached.”
Access the Media Library
- Log in to your WordPress dashboard.
- Locate the “Media” option in the left sidebar menu and click on “Library.”
Search for the Image
- In the Media Library, use the search bar at the top right to find the image you want to locate.
- Click on the image thumbnail to open the Attachment Details window.
Check the “Uploaded to” Section
- In the Attachment Details window, find the “Uploaded to” section on the right-hand side.
- This section will display the page’s name or post where the image is used, along with a clickable link. The “Uploaded to” section is missing if the image was not uploaded through a post or page.
Bonus tip: You can also check the “Uploaded to” column when switching the Media Library to the list view as shown in the next screenshot.
Using Image Source Control
Image Source Control creates an index of images within certain posts and pages. Compared to the “Uploaded to” section in the Media Library, it will list more than one post or page if the image is used multiple times.
The ISC index also contains images that are outside of the typical content, e.g., in the sidebar or header, or when they are added dynamically through a block or shortcode.
Safely remove unused images
Image Source Control also comes with the ”Unused Images“ overview, which you can use to check and safely delete unused images in bulk.
Open the Image-Post Index
- Log in to your WordPress dashboard.
- Locate the “Media” option in the left sidebar menu and click on “Image Sources.”
- Click on the “list image-post relations” button in the “Debug” section.
- Look for the image title in the table and find posts using the image in the right column.
Click on the post title to go to the appropriate edit page. It is best to check the frontend view of the post to see where it is actually used and then identify where it can be changed.
Did you know? Image Source Control can also generate a list of images on a site, including their authors on a dedicated page. Check out the list of all features.
Find used Images in the Database
If you have access to your WordPress site’s database, you can search image usages with SQL queries or the search provided by the database tool.
This method allows you to find all instances of an image, regardless of size variations, throughout your site’s content and options.
The first submethod is helpful if you have some knowledge of SQL to make adjustments, e.g., when your database prefix differs from the default. The second method needs knowledge about the structure of WordPress databases.
Exercise caution when working with your database to avoid unintentional data loss or corruption.
Identify the Image Filename
- Navigate to the Media Library in your WordPress backend and locate the image you want to search for.
- Make a note of the image filename (without the dimensions) and the file extension (e.g., .jpg, .png, .gif).
Example: If the image file is my-cute-dog.jpg
, the filename is “my-cute-dog,” and the extension is “.jpg.”
Access Your WordPress Database
- Log in to your web hosting control panel (e.g., cPanel).
- Locate the “Databases” section and click on “phpMyAdmin” or any other database management tool provided by your hosting provider.
- In phpMyAdmin or the chosen tool, select your WordPress database from the left sidebar.
Search Images in Content
The following queries will help you to find specific images in the content of posts, pages, and any other post types. Jump to the next section if there is a chance of an image being used in other sections, like options or metadata.
- In your database management tool, click the “SQL” tab or locate the SQL query editor.
- Enter the following query, replacing
wp_posts
with the actual name of yourposts
table (if it uses a different prefix), andIMAGE_FILENAME
with the appropriate information from step 1:
SELECT * FROM wp_posts
WHERE post_content LIKE '%IMAGE_FILENAME%'
AND post_type != 'revision';
Code language: JavaScript (javascript)
Example: If your image filename is “my-cute-dog,” your query should look like this:
SELECT * FROM wp_posts
WHERE post_content LIKE '%my-cute-dog%'
AND post_type != 'revision';
Code language: JavaScript (javascript)
- Execute the query. The search results will display all posts and pages where the image is used, regardless of its dimensions.
As you might have seen, my query excludes “revisions.” These are previous versions of your post that WordPress creates automatically. They allow you to see the history of a post over time and revert changes. There are normally a lot of them stored in the database, which would create noise in the results.
Usually, the images appear in the post_content
field. Use the ID or the title from the post_title
field to search for the post or page in your WordPress backend.
Use regular expressions
The SQL query above has a caveat with short filenames.
Imagine I just used “dog.” Depending on my site, there could be a lot of results from posts containing the word “dog” but not the image I was looking for.
To find fewer unique image files, we need to include the file extension in the search. At the same time, we need to consider that WordPress uses variations of image files, e.g., dog-1024x400.jpg
.
An appropriate SQL query for our example would be the following:
SELECT * FROM wp_posts
WHERE post_content REGEXP 'dog[^[:space:]]*\\.jpg'
AND post_type != 'revision';
Code language: JavaScript (javascript)
The query finds image files with the original filename at the beginning and any non-space characters between the extension.
Search Images Everywhere
Sometimes, an image is not only part of the content but also used in options or metadata. It might then be useful to widen the search to anywhere in the database. While this method does not include using SQL, identifying the results needs more knowledge about WordPress’ database structure than looking for images in the content.
This can be done with the general search form in phpMyAdmin.
- Open phpMyAdmin.
- Select the database you want to search in.
- Navigate to the “Search” tab in the top navigation.
- Fill in the image filename and file extension in the search field under “Search in database.” Separate them using space.
- Select “all of the words” in the “Find” section.
- Select the relevant tables in the “Inside tables” section. If you have many or very large tables, it might be useful to select individual ones.
- Click “Go” to run the search.
If you are an advanced user, you could also use a regular expression. Taking our example dog[^[:space:]]*\\.jpg
from above, you need to remove the double backslash for the search to work, i.e., dog[^[:space:]]*\.jpg
.
You will probably see more results than just searching through the content. This is because image information themself are stored in the database, and revisions are not excluded either.
So for a better result, I would suggest running the SQL query to find images in the content first and then exclude the wp_posts
table from the search. You might also exclude wp_postmeta
limiting the results solely to non-content elements.
Identifying relevant results might take some knowledge about where and how WordPress, or certain plugins, store information in the database. E.g., options are often stored in a serialized array, which might need some experience or an external tool to interpret.
Using the Post Search in the WordPress Backend
Another method to find used images on your WordPress site is the built-in post search in the backend. This method allows you to search for image filenames within your site’s content, which can help you locate where the image is being used.
Identify the Image Filename
- Navigate to your Media Library and locate the image you want to search for.
- Make a note of the image filename without the extension.
Note: Alt texts or captions added to the Media Library might work, too, as search terms. When an image is added to the content, WordPress uses the alt text from the Media Library in the post content as well. However, from this point, changes to the alt text in your Media Library would not change the alt text in your post and vice versa. So the results of such a search are not reliable.
Use the Post Search Functionality
- In your WordPress dashboard, click on “Posts” in the left sidebar menu.
- Locate the search bar at the top right corner of the “Posts” screen.
- Enter the image filename from Step 1 into the search bar and click “Search Posts.”
- The search results will display all posts that contain the entered image filename.
- Click on each post in the search results to open the editor and verify the image usage.
To ensure that you find all instances of the image on your site, repeat the search for pages by clicking on “Pages” in the left sidebar menu of your WordPress dashboard and using the search functionality.
Using Google Image Search
Google Image Search is a powerful tool that can help you locate instances of an image not only across the internet but also just on your own site. By using Google’s reverse image search feature, you can find where an image is used by searching for the image URL or by uploading the image itself.
Locate the Image URL or Download the Image
- Navigate to your WordPress Media Library and locate the image you want to search for.
- Either copy the image URL from the Attachment Details window or download the image to your computer.
Do a Reverse Image Search
- Open your web browser and visit the Google Images homepage.
- Click on the camera icon in the search bar to access the reverse image search feature.
- You have two options in the Google Images reverse search window: a. Paste the image URL into the “Paste image URL” field and click “Search by image.” b. Click “Upload an image” and choose the downloaded image from your computer.
- Google will perform a reverse image search and display the search results.
Filter the Search Results for Your Site
If the image is used on more than just your website, you can narrow it down by entering site:YOURSITE
into the search form. Replace “YOURSITE” with the homepage URL of your website.
Google will now display search results for instances of the image on your site. I have tried this with various images and found instances where Google missed a URL. Since Google index and their Image Search are a black box, it might only give you a quick overview, but you should not rely on it.
Conclusion
In this tutorial, I tested a few methods for finding where an image is used on your WordPress site:
- “Uploaded to” information in the Media Library
- Using Image Source Control
- Search the database directly
- Post Search in the Backend
- Google Images reverse search
Each method has its own benefits and drawbacks, so choose the one that best fits your needs and technical expertise.
I recommend Image Source Control for teams and less technical editors since it indexes images on multiple posts and even outside of the content. When I am not sure if an image might be used outside of the content, I use the database search. It takes significantly more time, so I only do it when there is a reason to think an image is used in unusual spots.
By regularly monitoring and managing your site’s images, you can maintain a clean media library, improve site performance, optimize SEO, and ensure that your content remains up-to-date and relevant.
If cleaning up the media library is your main goal, check out Find unused images in WordPress.
Questions? Feedback? How can I help?
Reach out directly via the contact form.