WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#41737 new enhancement

Possibly redundant template files in the hierarchy

Reported by: danburzo Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Themes Keywords: close
Focuses: template Cc:

Description

Hi,

As I'm building https://forklor.github.io/wp-template-hierarchy/ (still a work in progress) and sifting through the source code, it looks like the following template files in the hierarchy may be redundant:

  1. ${subtype}.php for attachments — is there a need for a template for a subtype without its associated ${mime_type}? Is there a use-case am I missing where a subtype may be associated with different mime types?
  1. attachment.php can be caught in single-attachment.php.

For the sake of simplifying WP's API surface, I am proposing deprecating these templates in a future version.

And as a related question (let me know if I should open a separate issue), to preserve symmetry with other post types and and pages, should a Custom Post Template set for an attachment not get priority before the other attachment templates?

(Please let me know if I misunderstood anything!)

Change History (3)

#1 @danburzo
2 years ago

For convenience, here's where the relevant code is located:

And a few related issues I found:

  • attachment.php is too high in priority: #38160
  • attachment.php is usually missing in themes: #41461
  • attachment uploaded to Page goes on to page.php instead of single-....php: #33017

In regards to Custom Post Templates to apply to single attachments, posts, and pages, maybe have a get_custom_template() method in template.php that gets called in template-loader.php before is_attachment() / is_single() / is_page()?


On the topic of deprecation, I salute the demise of paged.php — I could not wrap my head around how to use it :P.

Last edited 2 years ago by SergeyBiryukov (previous) (diff)

#2 @SergeyBiryukov
2 years ago

  • Component changed from General to Themes

#3 in reply to: ↑ description @johnbillion
2 years ago

  • Keywords close added
  • Version trunk deleted

Replying to danburzo:

Is there a use-case am I missing where a subtype may be associated with different mime types?

It's rare, but yes this does happen. Mime types for Ogg files work like this, with video/ogg and audio/ogg.

attachment.php can be caught in single-attachment.php.

Yeah, the attachment template hierarchy has gotten a bit messed up. Deprecating or removing this doesn't provide much benefit, so I'd be hesitant to deprecate it.

See #38160 for more attachment template hierarchy weirdness.

Note: See TracTickets for help on using tickets.