What are file attachments in WordPress, and how can they improve your site? Well, the reason to attach any file is to enhance the visitor experience in some way. There are several file types you can add to a WordPress post or page. Let’s dig a little deeper.
Types of WordPress Attachments
Any media file you add to your WordPress post or page is an attachment. The most common types are images, video, podcasts, or other audio. You can also attach document files for visitors to download, such as PDF files, presentations, and spreadsheets.
Why bother with attachments
Written content is crucial for the survival of any WordPress website or blog. But a page full of text-only is uninviting, even when it’s well written and interesting. Imagine an online glossy magazine or newspaper void of images or other media. Attachments bring the text to life and make the content visually appealing and more engaging.
At least 65% of people are visual learners. Images attached to a post or page makes the piece easier to read, and that’s the point. Videos and podcasts also add something extra when used correctly. And free downloads help to build trust and grow your fan base.
WordPress Media Library
Every image, video, audio, and document you attach to your content saves to the WP Media Library. It lists the most recently uploaded files first, but you can also control and sort the content. Your Media Library is the place to keep attachments that you may want to reuse.
Log in to your WP Dashboard to access the WP Media Library.
Click Media => library from the side menu.
 Your WP Media Library offers the following functions:
- Upload new files via the add media button
- Display media type
- Display by date
- Bulk select
- Search (useful for huge libraries)
Here’s how it looks in grid view; displaying equal-sized thumbnails for all files.
Below is how your media library looks in list view. When you hover over an attachment, you have links to Edit, Delete Permanently, or View the file.
Managing your media library
Managing your WP Media Library is quick and easy. You can sort, edit, or delete uploaded attachments as necessary. Editing a file changes the attachment details automatically.
Here are the edit screen options for a media image file.
Add file attachments to your media library.
Adding file attachments to your media library is a straightforward process.
Click the Add New button from the Media Library screen.
Either drag-and-drop files into the Media Library or select them from your computer. You also want to note the maximum upload file size allowed in the Upload New Media screen.
How to attach media files to your posts and pages
Attaching media files to WordPress posts is a painless process.
From your WP Dashboard, click Posts => All Posts.
Hover the mouse over the published or draft post title and click the Edit link.
Your post or page is now open in edit view.
- Put the cursor where you want the file attachment to go
- Click Add Block symbol (+) top open the blocks column
- Choose the media file you want to attach from the Blocks column
Let us add an image file for this example. Click the Image block above.
The Image Block opens and gives you 3 options to add the attachment.
- Upload a new image
- Attach a previously uploaded image from the Media Library
- Insert an image from a URL
All Add Media blocks look similar, but they don’t all have the option to Insert items from URL.
About Image Attachment Pages
WordPress creates an attachment page for every file type you add to the Media Library. These pages are useful for displaying single image files with photography and art portfolios. Most WP users prefer web searchers to find the post or page the image belongs to. That might not happen if the attachment page ranks higher in the search engines than the image in the post.
How to disable attachment pages for image files
The way to avoid image attachment pages ranking better than content pages is via WordPress plugins. YOAST is a popular option, so you can use that if you already have it activated.
From the WP Dashboard menu, click Y SEO => Search Appearance.
- Click the Media tab on the Yoast screen
- Set “Redirect attachment URLs to the attachment itself?’ to Yes
- Click Save Changes
There are other plugins if you don’t have—or prefer not to use—Yoast. One of those is called ‘Attachment Pages Redirect.’ If you do want to use a plugin, always make sure the current version is compatible with your release (version) of WordPress.
Related reading: How to Install New Plugins in WordPress.
Disable Attachment Pages with Code
You can disable attachment pages using the code below if you prefer not to use a plugin.
<?php wp_redirect(get_permalink($post->post_parent)); ?>
For this, you need to create a file called image.php and upload it to the active theme folder. A text editor like Notepad ++ will do. Remember to save the new file with the PHP extension.
If you already have an image.php file in the themes folder, download it to your computer. Save an extra copy somewhere as a backup in case of issues.
- Open the image.php file
- Paste the code above onto the first line
- Save the file
- Re-upload the image.php file to your server, overwriting the original
If a search engine sends someone to your image attachment pages now, they get redirected to the content or parent page. This approach only works for the theme in use. Plugins work with whatever theme you happen to be using from your WordPress login.
Closing Comments
The creative use of attachments brings your WordPress posts and pages to life. It’s easy to add, remove, swap, store, edit, and upload a file attachment using your Media Library. Remember to disable or redirect files from single attachment pages unless you want them to rank.