Where are images stored in WordPress?Understanding Database, Media Library, and File System

Learn where WordPress stores image data in the database and file system.

Whether you’re a website owner, developer, or just curious about the inner workings of WordPress, understanding how and where images are stored can be crucial for maintenance tasks like deleting unused images. While developing Image Source Control, I learned much about how and where WordPress stores pictures and created the ultimate resource for you to get the same insights quickly.

WordPress Media Library: An Overview

The WordPress Media Library is a centralized hub for managing all your website’s media files, including images, videos, and documents. It provides an intuitive interface for uploading, organizing, and inserting media into your content. The Media Library is more than just a visual tool; it’s deeply integrated with WordPress’s file system and database.

Key functions of the Media Library

  • Uploading and storing media files
  • Organizing media with folders and tags
  • Editing image metadata like photo credits or author attributions
  • Inserting media into posts and pages
  • Generating different image sizes

Where Are Images Stored in WordPress?

When you upload an image, WordPress stores it in two places: the file system and the database.

Let’s first look at the file system storage.

File System Storage

WordPress stores the actual image files on your server’s file system. By default, these files are located in the /wp-content/uploads/ directory of your WordPress installation. This directory is usually organized by year and month, creating a structure like this:


This organization helps keep your uploads tidy and can improve performance by limiting the number of files in a single directory.

You can change this behavior and store all (new) files directly in the uploads folder by turning off the checkbox under Settings > Media > Uploading Files.

The option in WordPress to change where images are stored in WordPress’ file system.
Disable the checkbox to store all media files in the same folder.

WordPress Database and Image Storage

While the actual image files reside in the file system, WordPress uses its database to store important information about each image. This information is crucial for managing and displaying images throughout your site.

What image information is stored in the database?

  • File name and path
  • Image title, caption, and description
  • ALT text
  • Dimensions
  • File size
  • Upload date
  • Attachment ID (a unique identifier for each media item)

Where is the WordPress Media Library Stored in the Database?

The WordPress Media Library information is primarily stored in two database tables:

  1. wp_posts
  2. wp_postmeta

wp_posts Table

The wp_posts table stores the main information about each media item. When you upload an image, WordPress creates a new entry in this table with a post_type of attachment.

Key fields in wp_posts for media items:

  • ID: Unique identifier for the attachment
  • post_title: The title of the image
  • post_name: A sanitized version of the file name
  • post_content: The image description
  • post_excerpt: The image caption
  • post_type: Set to attachment for media items
  • guid: The URL of the full-size image

wp_postmeta Table

The wp_postmeta table stores additional metadata for each media item. This includes information like image dimensions, file type, and custom fields.

Important metadata stored for images:

  • _wp_attached_file: The relative path to the image file
  • _wp_attachment_metadata: A serialized array containing information about image sizes, dimensions, and more

Plugins also add metadata to wp_postmeta. Image Source Control, for example, uses the key isc_image_source to store the photo credits and author information.

Customizing WordPress Image Storage

While the default WordPress image storage system works well for most sites, you may sometimes need to customize it.

Changing Upload Directories

You can modify the upload directory by adding this code to your wp-config.php file:

define( 'UPLOADS', 'wp-content/my-custom-uploads' );Code language: JavaScript (javascript)

This will change the upload directory to /wp-content/my-custom-uploads/.

Using Plugins for Image Storage

Several plugins can help you manage and optimize your WordPress image storage:

  • WP Offload Media lets you store your media files on cloud storage services like Amazon S3.
  • Media Cloud offers advanced media management features, including cloud storage integration and on-the-fly image optimization.
  • Enable Media Replace lets you replace existing media files without breaking links.

Best Practices for WordPress Image Management

To ensure optimal performance and maintainability, follow these best practices:

  1. Optimize images before uploading: Many image generators or editing tools can decrease the file size of images. I use the web service TinyPNG or the ShortPixel plugin.
  2. Use appropriate image formats: Choose JPG for photographs, PNG for transparent graphics, and WebP for modern browsers. I am increasingly using the latter since it is small by default and widely supported by browsers.
  3. I am indifferent towards lazy loading: This technique defers the loading of images until needed, improving page load times. However, more knowledgeable people claim that the impact on SEO is small.
  4. Regularly back up your uploads folder and database: This ensures you can recover your images if something goes wrong.
  5. Use Image Source Control to delete unused images and metadata from your database.

Advanced Topics

Using Content Delivery Networks (CDNs) for Image Storage

CDNs can significantly improve your site’s performance by serving images from servers closer to your users. Plugins like WP Rocket or CDN Enabler can help you integrate a CDN with your WordPress site.

These plugins connect your site to a CDN and load images from there. This can increase your page loading speed but might conflict with other plugins that rely on the original image path. I had a few cases with Image Source Control like this, but I was able to resolve them.

Handling Image Storage in Multisite Installations

WordPress Multisite uses a slightly different structure for storing uploads. By default, each site in the network has its own uploads directory:

/wp-content/uploads/sites/2/Code language: JavaScript (javascript)

You can also configure a multisite to use a shared uploads directory for all sites, though, in most cases, it might make sense to keep them separated.


Understanding where and how WordPress stores images is crucial for effective website management. By leveraging both the file system and database, WordPress provides a robust and flexible system for handling media files. Whether you’re troubleshooting issues, optimizing performance, or customizing your site’s functionality, this knowledge will prove invaluable.

Take a look at my Image Source Control plugin if you want to accomplish advanced tasks like deleting unused images or reliably showing author attributions using image captions.

Portrait of Thomas Maier, founder and CEO of Image Source Control

Questions? Feedback? How can I help?

Reach out directly via the contact form.