Media Library & Files

This article is part of the WordPress guide. Read the introduction.

Table of Contents

Media in WordPress are managed using the Media Library. You can get there by heading to the ‘Media’ menu on the left or to the /wp-admin/upload.php URI. In there, you can drop in all kinds of files – images, PDFs, binary files, and even videos. You can delete files as well. You can also modify files’ titles, captions, descriptions, and alternative texts.

Every file is a post, feeding into the “Everything is a post” mentality. Its post type is ‘attachment’. All of these files are stored in the /wp-content/uploads/ directory. By default, they are organized in /yyyy/mm/ subdirectories. This means that if it’s August 2025, and you upload a file, it’ll be placed in /wp-content/uploads/2025/08.

You can change this behavior by unchecking the “Organize my uploads into month- and year-based folders” checkbox in Settings > Media. If you do that, all of your files will be uploaded straight to the /wp-content/uploads/ directory. Keep in mind that the directory can become very large very fast, especially if you have a media-heavy website.

Image Sizes

One of the most powerful features of WordPress’s media system is image sizes. When you upload an image in the Media Library, WordPress automatically generates various different registered sizes of that image. Let’s look at it in more detail.

The add_image_size( $name, $width, $height, $crop ) function allows you to register a new image size. Every image uploaded from then on will have an additional version file generated following this pattern: {original_slug}-{width}-{height}.{file_extension}. How the image will be scaled depends on the $crop argument. You can either not crop at all (default), crop from the center, or crop from a specified position (left/center/right and top/center/bottom).

Let’s assume you registered a 500×500 image size without cropping, and you uploaded a “cat.png” file with a native size of 1000×800. The additional generated file will be named “cat-500×400.png”. You can see the image got scaled without distorting the aspect ratio.

All built-in WordPress functions responsible for getting/displaying images accept a size argument. Let’s say you registered your custom size with the name “square-medium”. You can call wp_get_attachment_image( $attachment_id, ‘square-medium’ ). This will return the HTML of an img element linking to the 500×400 version.

There are a few image sizes registered by default. Some of them you can modify manually in Settings -> Media. Those are: thumbnail (150×150), medium (300×300), and large (1024×1024). Thumbnail is cropped by default, while all the other sizes are scaled proportionally. There’s also a default medium-large size (768×768), which, interestingly enough, cannot be modified in settings.

Image sizes are not separate posts. Information about them is stored in the wp_postmeta table. Every attachment post has a “_wp_attachment_metadata” entry. This entry stores a lot of the information about the image, including all of the generated sizes and the file’s innate metadata.

PS: Images added in the past will not be regenerated after registering a new image size. You’d have to use a plugin for that.

Table of Contents