get_attachment_template
Retrieve path of attachment template in current or parent template.
Description
(string) get_attachment_template();
The hierarchy for this template looks like:
1. -.php 2. .php 3. .php 4. attachment.php
An example of this is:
1. image-jpeg.php 2. jpeg.php 3. image.php 4. attachment.php
The template hierarchy is filterable via the hook. The template path is filterable via the hook.
Returns (string)
Full path to attachment template file.
Usage
if ( !function_exists( 'get_attachment_template' ) ) { require_once ABSPATH . WPINC . '/template.php'; } // NOTICE! Understand what this does before running. $result = get_attachment_template();
Defined (1)
The function is defined in the following location(s).
- /wp-includes/template.php
- function get_attachment_template() {
- $attachment = get_queried_object();
- $templates = array();
- if ( $attachment ) {
- if ( false !== strpos( $attachment->post_mime_type, '/' ) ) {
- list( $type, $subtype ) = explode( '/', $attachment->post_mime_type );
- } else {
- list( $type, $subtype ) = array( $attachment->post_mime_type, '' );
- }
- if ( ! empty( $subtype ) ) {
- $templates[] = "{$type}-{$subtype}.php";
- $templates[] = "{$subtype}.php";
- }
- $templates[] = "{$type}.php";
- }
- $templates[] = 'attachment.php';
- return get_query_template( 'attachment', $templates );
- }