Disable Image Attachment Pages in WordPress

WordPress has so many different “stock” template types that are not used on every type of website. For example, a small business website, may not use the Archive, Blog or Single page layouts.

In my seven years of building WordPress website, I have yet to come across a single client that uses the “Attachment Page” layout (properly, at least).

Yet, when inserting Media items into content, it’s one of the available options:

attachment page wordpress screenshot

If there’s a way to remove this option from WordPress core, I would love to know about it. Please leave me a comment.

In the meantime, to disable access to this file type, create a file called image.php in your Theme folder and paste the following into it:

<?php wp_redirect(get_permalink($post->post_parent)); ?>

Source.

Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.