What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
In a classic WordPress theme, create attachment.php for a layout shared by all attachment pages, or use a more specific file such as image.php or image-jpeg.php when the design should apply only to particular media. Block themes use the corresponding .html templates in the theme’s templates directory. WordPress selects the most specific matching template first, then falls back to general attachment and singular templates.
Choose the right attachment template
Use the narrowest template that matches the layout you want. WordPress checks the MIME type and subtype before using a general attachment template.
| Template | What it matches | Theme type |
|---|---|---|
attachment.php |
All attachment types when a more specific file is absent | Classic PHP theme |
image.php, video.php, audio.php, or application.php |
Attachments of the corresponding MIME type | Classic PHP theme |
jpeg.php |
A matching subtype, such as JPEG images, when no more specific MIME-and-subtype file takes precedence | Classic PHP theme |
image-jpeg.html, jpeg.html, image.html, or attachment.html |
Specific image subtype, subtype, image type, or all attachments, respectively | Block theme |
For a classic theme, the documented hierarchy is {mime_type}-{sub_type}.php, {sub_type}.php, {mime_type}.php, attachment.php, single-attachment.php, single.php, singular.php, then index.php. Thus, an image/jpeg attachment checks image-jpeg.php, jpeg.php, image.php, and attachment.php in that order before generic fallbacks. See the WordPress template hierarchy and the get_attachment_template() reference.
Create a template in a classic PHP theme
-
Use a child theme or your own theme. Put the template file in the theme root. Editing a vendor theme directly risks losing the change when that theme is updated.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteSpecial offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy. -
Create the matching file. Add
attachment.phpfor a general attachment layout. Chooseimage.php,video.php,audio.php, orapplication.phpto specialize by MIME type; use a subtype file such asjpeg.phponly when you need a narrower match. -
Keep the theme’s normal page structure. Include its header, loop, and footer so the attachment view fits the rest of the site.
-
Render the attachment and optional caption inside the loop. WordPress documents this pattern for showing an image and its excerpt when present:
<div class="entry-attachment"> <?php $image_size = apply_filters( 'wporg_attachment_size', 'large' ); echo wp_get_attachment_image( get_the_ID(), $image_size ); ?> <?php if ( has_excerpt() ) : ?> <div class="entry-caption"> <?php the_excerpt(); ?> </div> <?php endif; ?> </div>wp_get_attachment_image()is the documented function used here to output the attachment image. See the Attachment Template Files guide and wp_get_attachment_image() reference.Recommended Free Tools
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.Rank #3
-
Add the presentation details. Apply your theme’s CSS and include metadata or other markup appropriate to the design and accessibility needs.
Create an attachment template in a block theme
Block themes use HTML templates rather than PHP files. Add the relevant file to the theme’s templates directory. The hierarchy mirrors the classic theme’s specificity order: {mime_type}-{sub_type}.html, {sub_type}.html, {mime_type}.html, attachment.html, then the default single hierarchy.
Rank #4
For an image/jpeg attachment, that means WordPress can match image-jpeg.html, jpeg.html, image.html, or the general attachment.html. Choose the most specific file that fits the intended design. The WordPress template hierarchy documentation describes the block-theme hierarchy.
If the attachment template does not load
First check whether the site exposes attachment pages and whether the visitor is opening the attachment page rather than the media file itself. WordPress’s Theme Handbook says, “As of WordPress 6.4, attachment pages are no longer enabled by default on new installations.” That qualification concerns new installations; do not assume every existing site has the same setting. Then confirm that the file is in the active theme’s expected location and that its name matches the attachment’s MIME type or subtype. A more specific matching file takes precedence over attachment.php.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Best Value
The template hierarchy can also be changed by attachment-template hierarchy filters, so a theme or plugin that customizes template selection may affect which file WordPress uses. The behavior and template names are documented in the Theme Handbook and function reference.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

