Confused with attachment mimetype order

Suppose I have attachments of MIME type image/png, image/jpeg and image/gif. And I have template files image.php and gif.php in my theme folder. So, this means that I want to customize a page displaying content of text/gif MIME type. Let’s assume that attachment.php is used for displaying the rest of the MIME types and I can’t use it for image/everything_except_gif. But the application will never get to the gif.php file (or image_gif.php) even though it describes a more specific case than image.php.

Now, if we look at taxonomies, everything works correctly. File taxonomy-sometax-term8.php will be used instead of taxonomy-sometax.php, because it describes a more specific case.

I did a search and found a suggestion to create a plugin, but why not make other query types behave the way attachments do and have us writing plugins for taxonomy/category/page/everything_else?

1 Answer
1

Yes, this does seem like a lapse in template hierarchy.

The easiest for case described would probably be handling logic in image.php, along the lines of (see get_attachment_template() for mime type retrieval):

if( 'gif' === $subtype ) {

    include 'gif.php';
}
else {

    // generic image template
}

For more complicated logic it might be worth just ignoring native order and overriding it with custom one for this branch of hierarchy.

Leave a Comment