Would you like to create a custom single attachments template in WordPress?
Individual images and other uploaded files on your website are displayed on a single attachments page. However, many themes don’t provide a template for attachments.
In this article, we’ll show you how to create a custom single attachments template in WordPress.
What Is an Attachments Page in WordPress?
By default, a single page is automatically created for every media attachment you have on your WordPress website. This includes images, videos, audio files, PDFs, and more.
Like posts and pages, attachments are stored in the
wp_posts table of your WordPress database. In fact, attachments are a special type of post and have the post type of ‘attachment’. This makes it easier to search for and display attachments.
Attachments pages allow you to add metadata to your file uploads, such as a title, caption, and description. They also allow your visitors to make comments on your images and videos.
Many users like to customize their attachments template to display additional information. For example, a photography theme could use the attachment page to display EXIF data. This could show the camera model used, the camera settings, and even the image’s location data.
However, if you don’t plan to make use of these attachments pages, then we recommend you disable them.
With that being said, let’s take a look at how to create a custom single attachments template in WordPress. Here’s what we’ll cover in this guide:
- How to View an Attachments Page in WordPress
- Which Template Is Used for an Attachments Page?
- Disabling Attachment Pages in WordPress
- Creating a Custom Single Attachments Template with a Theme Builder Plugin
- Creating a Custom Single Attachments Template Using Code
How to View an Attachments Page in WordPress
When customizing your single attachments template, it’s helpful to view an attachments page so you can see your changes. Here are a few ways to view attachments pages in WordPress.
Viewing an Attachments Page From the Media Library
You need to navigate to Media » Library and then click on an image or other attachment. The ‘Attachment details’ window will pop up.
Here you can enter the alt text, title, caption, and description of the image. This information can be shown on the attachments page, so it’s a good idea to fill in the fields so you can see how they are displayed.
At the bottom right of the window, you’ll see a ‘View attachments page’ link.
When you click on that link, you’ll be taken to the attachments page for that image.
Viewing an Attachments Page from a Post or Page
You simply need to open a post or page inside the WordPress content editor and then add an image.
Next, select the image and click on the ‘Link’ button on the toolbar. In the dropdown, you will see the option to select the ‘Attachment Page’.
Now when you click on the image, you will be taken to its attachment page.
Which Template Is Used for an Attachments Page?
If it exists, WordPress will use a template called
attachment.php to control the appearance of your attachments pages. However, you can also create different templates for each file type that can be uploaded to your site.
For example, a template file named
image.php will control how image attachment pages look, and video attachment pages can be controlled by a template called
You can even create a custom attachments template for specific file extensions. For example, the template
image-gif.php will control GIF image attachment pages.
However, if your WordPress theme doesn’t offer a specific template for attachments, then it will default to using
single.php, the single post type template, or
index.php, the default fallback template.
When that happens, your attachments pages will have the layout of any other post or page. This won’t always look good.
Disabling Attachments Pages in WordPress
If you don’t plan to use attachments pages in WordPress, then we recommend that you disable them.
Many themes don’t have special templates for attachments, so they can look like incomplete pages on your site. This can leave a poor impression on visitors.
They can also have a negative SEO impact on your search rankings. That’s because search engines consider pages with little to no text as ‘low quality’ or ‘thin content’.
You can learn more in our guide on how to disable image attachment pages in WordPress.
However, if you do plan to make use of attachment pages, then read on to learn how to customize the attachments template in WordPress. We’ll cover two methods. The first is the simplest and uses a plugin.
Creating a Custom Single Attachments Template with a Theme Builder Plugin
The easiest way to create a custom single attachments template is by using SeedProd. It’s the best WordPress theme builder plugin and can create beautiful website layouts and custom templates without writing any code.
You can use SeedProd to create a fully custom WordPress theme, including a custom single attachments template.
Note: There is a free version of SeedProd, but you will need the Pro version to access the theme builder and create a custom attachments template.
Upon activation, you need to enter your license key. You can find this information under your account on the SeedProd website.
After that, you need to use SeedProd to easily create a custom WordPress theme.
Creating a Custom WordPress Theme
You’ll find the SeedProd theme builder by navigating to the SeedProd » Theme Builder page. Here, you’ll use one of SeedProd’s ready-made themes as a starting point. This will replace your existing WordPress theme with a new, custom design.
You can do that by clicking the ‘Themes’ button.
You will be shown a list of professionally designed themes that are designed for different types of websites. For example, there are templates called ‘Modern Business’, ‘Marketing Agency’, and ‘Mortgage Broker Theme’.
Take a look through the options and select one that best matches your needs by clicking the checkmark icon.
Once you have chosen a theme, SeedProd will generate all the theme templates you need. Now you can create a custom single attachments template.
Creating a Custom Attachments Template
By default, there is no attachment template, and the Single Post template will be used for attachments, like this.
We’ll fix that by creating a new Attachments template. We’ll use the Single Post template as a starting point so that the new template is consistent with your theme.
To do that, you need to hover over the Single Post Duplicate the Single Post template until some links appear. You should now click the ‘Duplicate’ link to create a copy of that template.
You will now see a new template called ‘Single Post- Copy’ at the top of the list.
You need to point your mouse over the new template and then click the ‘Edit Conditions’ link that appears.
A window will pop up that allows you to change the template’s settings. You can start by giving it the name ‘Attachments’.
Next, you need to define the conditions when this template will be used. In the ‘Conditions’ section, leave the first setting as ‘Include’ and then select ‘Is Attachment’ from the second drop down menu.
After that, you need to give the template a priority. The Single Post template has a priority of 0, so you need to give this template a higher priority so that it will be used instead for all matching pages. For this tutorial, we’ll assign a priority of 5.
Once you’re finished, make sure you click the ‘Save’ button to store the new settings.
Now it’s time to customize the design and contents of the template. You can do that by clicking the ‘Edit Design’ link.
This will open the SeedProd page builder. Here you can add new content by dragging blocks onto the page, and rearrange the content using drag and drop.
You can access the settings for any block by clicking it, and when you hover over a block, you can delete it by clicking the Trash icon.
For this tutorial, we’ll delete the two blocks at the top of the page that are related to the blog, and drag the Post Info block so that it’s underneath the image.
We’ll also delete the comments section at the bottom of the page. When you’re finished, make sure you click the ‘Save’ button at the top of the page. After that, you can close the page builder by clicking the ‘X’ button in the top right.
You’ll now find yourself back at the templates list. You will need to activate the new template by switching the ‘Published’ toggle to the on position.
You can now view an attachment page on your website to see the changes.
Creating a Custom Single Attachments Template Using Code
This method is more advanced, and you will have to add code to your WordPress theme’s template files. If you haven’t done this before, then see our guide on how to copy and paste code in WordPress.
You will lose many of your theme customizations when you install an update to your theme. We recommend you avoid that by creating a child theme and customizing it instead. You can learn more in our guide on how to update a WordPress theme without losing customization.
Creating an Attachment Template File
First, you need to decide on which template you are going to customize. To change the way that all attachments look, you will need to customize
attachment.php. However, if you want to customize only your images or videos, then you’ll need to edit
Next, you need to see if your theme already contains those template files. For example, you’ll find the templates for the Twenty Twenty-One theme by visiting the
wp/content/themes/twentytwentyone folder on your WordPress hosting file manager.
We can see that the Twenty Twenty-One theme has an
image.php template but not a
If your theme doesn’t have the template you wish to customize, then you will have to create it. Simply save a blank file with the file name that you need.
Next, you need to copy the contents of the
single.php file into your new blank file and then save it. This will make sure your attachments template is visually consistent with the rest of your website.
You now have a new attachments template, but so far your attachments pages will look the same as they did before. It’s time to make some customizations.
Customizing the Attachment Template File
Now you can customize your attachments page by making changes to the code in the template. The template file is like any other theme file in WordPress. You can add any HTML, template tags, or PHP code to this file.
You can download the template to your computer and open it in any text editor, such as Notepad. When you have finished modifying the code, simply save the file and upload it back to your theme folder using FTP.
Here are some examples of how you might customize the
image.php template of the Twenty Twenty-One theme. This is how it looks before we make any changes.
The page starts with the image’s title, followed by the image itself and a caption. After that, you find an image description and some other details about the image. Finally, the comment section is displayed.
You can rearrange the order that which these sections are displayed. For example, you could move the code for the image above the title.
You can also remove the image caption by simply deleting the lines of code that display it.
Here’s how the attachment page looks now.
If you would prefer not to allow your visitors to leave comments on your images, then you can remove the comments section altogether.
Simply delete the lines of code near the bottom that display the comments section.
We hope this tutorial helped you learn how to create a custom single attachments template in WordPress. You may also want to learn how to embed a Facebook video in WordPress, or check out our list of the best Instagram WordPress plugins.