What Is Attachment In WordPress?

WordPress Attachment is a file which can be uploaded to a page or post in your site. This could be an image, video or audio clip etc., or it could be a file which has a clickable link that WordPress creates when you upload the file.

An attachment is a post type in WordPress. It is one of the post types that comes with WordPress out of the box.

Difference between an attachment and file upload in WordPress

Uploading a file using the Add Media button from the post or a page edit screen, the file you will be uploading will be an attachment of the post or page. You can also upload a file from the Media Library. It is not associated to a post or page, therefore, doesn’t exist as an attachment in the WordPress.

Or we can say, any file you upload from a page or post using the Add Media button, the PixelRockstar Add Stock photo button or as a featured image, it automatically becomes an attachment of your post or page.

How to create attachment pages?

If your WordPress theme doesn’t have an attachment.php file, you will have to create it.

If it is a theme created just for you, you may add the file now. In case, you are using a third party theme which you have downloaded or installed from the repository you must create a child theme.

Child themes are usually used to extend the existing themes without editing the original files. And once you’re done adding a child theme, you can create an attachment.php file in it.

Find the single.php file in your theme, copy the whole content of the file and paste it into the attachment page that file you have just created. Around 70% of the themes provided there, this should be enough.

In a large portion of the remainder, you might wish to delete some single post specific things. In some other cases, due to the way your single post page works, this may not work as expected. If this is so, try to use the content of page.php instead.

Installation

  • Download the plugin and extract the files
  • Upload attachments to your ~/wp-content/plugins/ directory
  • Activate the plugin through the ‘Plugins’ menu in WordPress
  • Implement Attachments in your theme’s functions.php or your own plugin (see Other Notes > Usage)
  • Update your WordPress templates where applicable (see Other Notes > Usage)

Benefits of attachment

First of all, attachment pages always exist on your site no matter the users visit them or not. This means that they could potentially be discovered by search engines easily. Then why not make them both search engine and user-friendly, by choosing relevant images for your content, writing nice captions and image descriptions you can add that much more relevant content to your site, increasing your SEO standing while providing more for your users to do in your page.

Since attachments are those posts which also have their own comments. If you would like your users to interact with your images, attachment pages are a great place to do this. This is especially relevant for photographers, artists, musicians and many more.

The attachment page is also a way of judging whether a theme developer takes his/her theme seriously. If the attachment page shows the same care and attention to all the detail as other pages do it is a good indicator of a decent theme.