WordPress Managed Hosting - 40% Off For 4 Months - Coupon Code: BFCM2021 Avail Now

How To Integrate WordPress Media & Attachment Pages to WordPress

Moeez — December 19, 2016 4 Minutes Read
WordPress Media and Attachment Pages

When creating the sitemap for your WordPress website, you usually forget that the attachments you put in your posts such as images, audios, videos or anything can have its separate page of its own. Just like any other posts, these attributes can have their own pages as well though they are not very well known in WordPress.

To organize them and make it well-formed containing relevant information, you can add a bit of more depth to them. Usually, users do that to increase the SEO score on their website. You can craft these pages in such a way that other media-related users can comment on it.

Today, I am going to shed a bit of light on this obscure page type and how you can add them to your WordPress theme so every media file that you upload can have a separate page of its own.

Let’s begin

WordPress Media & Attachment Pages

Most themes support not all attachment pages that the WordPress automatically creates, henceforth, it is necessary that one should know what these pages are and how you can add them to your website.

The significance of having an attachment page is that it can help you index proficiently in both, search engines and other social media platforms on the Internet. So let’s take a closer look at what these attachment pages can do and what can we do with them.

Just like any other page in WordPress, attachment pages are also stored as posts. Let’s assume that you attach an image to your WordPress website; it requires a title, an author, and a publication date. Same is the requirement for an attachment page; however, with an additional attribute, image location which is automatically stored in the post-meta table.

Here is an example how your attachment page may look like to the visitors viewing your website.

WordPress Media & Attachment Pages

You can add a small description of the image as well as describe it a little right underneath it. It is a static page provided with a date of publication. You can further Edit the size of the image using the provided option.

Finding out Whether Your Theme Has an Attachment Page or Not

To create an attachment page on your WordPress website, open up an old post on your website and click on any image present in the Post Editor. You will see an option bar appear on the top of the image. Select the edit option and change the “Link To” option to “Attachment Page”. Update and Publish it.

finding-out-whether-your-theme-has-an-attachment-page-or-not

Now visit the front-end of your website and check whether the image becomes clickable or not. If yes, then click the image, and it will automatically navigate you to a new attachment page. It may not look as good as the attachment image above because it depends on whether your current theme supports attachment pages or not.

This is because WordPress strongly depends on the template hierarchy. Every time you visit a page on your WordPress website, data is determined from this hierarchy.

The front page of your website uses index.php if it’s a post, if it’s a page then it uses page.php and only a single post then it uses single.php and thus the hierarchy expands depending on your custom website requirements.

If a certain page fails to exist in your WordPress template directory, then it automatically redirects to archive.php and extract data from there.

One way or another, it all goes down to the index.php. It is used whenever files further up in the template aren’t properly defined. Theme authors are used to specifying single pages, archives, 404 pages and such, but many forget about the archive page. They forget to implement it and thus index.php is used instead to execute the functions of archive.php.

Archive.php is the source template where theme authors implement a separate template called attachment.php which ensures that your attachment page looks fine. However, if it is not catered and configured correctly, you will get uncanny attachment pages.

Creating Attachment Pages

Assuming that your theme does not support attachment pages, you will simply have to create one if you want your images to be displayed as a separate attachment page. To do so, you will have to create an attachment.php file.

Well, if it is a predefined theme then need not to worry, all you have to do is add the file attachment.php file to it. However, if it is a third party theme, you downloaded, installed and activated it; you will have to create a child theme. With child theme, you can add a theme extension to your current theme without editing the original file. Once you successfully add the child theme, all you have to do is create an attachment.php file in it.

Learn here How You Can Create a Child Theme in Your WordPress

Then find the single.php file in your theme and then all you have to do is copy and paste the content available on the attachment page which you recently created. This method proficiently works in most theme cases. However, in certain scenarios, you might want to tweak up a little more as it will fail to function with single post page works. In such cases, my recommendation would be to use page.php instead.

So that would be all folks, hope you are well acknowledged about what WordPress Media and relative Attachment Pages are and how you can integrate them with your WordPress. If you like the article, please share it and feel free to leave a comment in the section below.

Create Faster WordPress Websites!

Free eBook on WordPress Performance right in your inbox.


    Create Faster WordPress Websites!

    Free eBook on WordPress Performance right in your inbox.

      Moeez is ‘The’ blogger in charge of WPblog. He loves to interact and learn about WordPress with people in the WordPress community. Outside his work life, Moeez spends time hanging out with his friends, playing Xbox and watching football on the weekends. You can get in touch with him at moeez[at]wpblog.com.

      THERE'S MORE TO READ

      Newsletter

        WordPress Help Zone - Ultimate WordPress Pit-Stop

        Learning WordPress? Or are you expert enough to help others? Join our WP Facebook group!