Title: is_attachment
Published: April 25, 2014
Last modified: August 20, 2026

---

# is_attachment( int|string|int[]|string[] $attachment = '' ): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#return)
 * [More Information](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#wp--skip-link--target)

Determines whether the query is for an existing attachment page.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#description)󠁿

For more information on this and similar theme functions, check out the [ Conditional Tags](https://developer.wordpress.org/themes/basics/conditional-tags/)
article in the Theme Developer Handbook.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#parameters)󠁿

 `$attachment`int|string|int[]|string[]optional

Attachment ID, title, slug, or array of such to check against.

Default:`''`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#return)󠁿

 bool Whether the query is for an existing attachment page.

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#more-information)󠁿

 * See Also: [is_singular()](https://developer.wordpress.org/reference/functions/is_singular/)
 * For more specific checking of the attachment see: [wp_attachment_is_image()](https://developer.wordpress.org/reference/functions/wp_attachment_is_image/)

## 󠀁[Source](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#source)󠁿

    ```php
    function is_attachment( $attachment = '' ) {
    	global $wp_query;

    	if ( ! isset( $wp_query ) ) {
    		_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
    		return false;
    	}

    	return $wp_query->is_attachment( $attachment );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/query.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/query.php#L213)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/query.php#L213-L222)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Query::is_attachment()](https://developer.wordpress.org/reference/classes/wp_query/is_attachment/)`wp-includes/class-wp-query.php` |

Determines whether the query is for an existing attachment page.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [_doing_it_wrong()](https://developer.wordpress.org/reference/functions/_doing_it_wrong/)`wp-includes/functions.php` |

Marks something as being incorrectly called.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#)

| Used by | Description | 
| [wp_embed_excerpt_attachment()](https://developer.wordpress.org/reference/functions/wp_embed_excerpt_attachment/)`wp-includes/embed.php` |

Filters the post excerpt for the embed template.

  | 
| [get_adjacent_post_link()](https://developer.wordpress.org/reference/functions/get_adjacent_post_link/)`wp-includes/link-template.php` |

Retrieves the adjacent post link.

  | 
| [get_adjacent_post_rel_link()](https://developer.wordpress.org/reference/functions/get_adjacent_post_rel_link/)`wp-includes/link-template.php` |

Retrieves the adjacent post relational link.

  | 
| [adjacent_posts_rel_link_wp_head()](https://developer.wordpress.org/reference/functions/adjacent_posts_rel_link_wp_head/)`wp-includes/link-template.php` |

Displays relational links for the posts adjacent to the current post for single post pages.

  | 
| [get_boundary_post()](https://developer.wordpress.org/reference/functions/get_boundary_post/)`wp-includes/link-template.php` |

Retrieves the boundary post.

  | 
| [wp_list_pages()](https://developer.wordpress.org/reference/functions/wp_list_pages/)`wp-includes/post-template.php` |

Retrieves or displays a list of pages (or hierarchical post type items) in list (li) format.

  | 
| [get_post_class()](https://developer.wordpress.org/reference/functions/get_post_class/)`wp-includes/post-template.php` |

Retrieves an array of the class names for the post container element.

  | 
| [get_body_class()](https://developer.wordpress.org/reference/functions/get_body_class/)`wp-includes/post-template.php` |

Retrieves an array of the class names for the body element.

  | 
| [redirect_canonical()](https://developer.wordpress.org/reference/functions/redirect_canonical/)`wp-includes/canonical.php` |

Redirects incoming links to the proper URL based on the site url.

  |

[Show 4 more](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/is_attachment/?output_format=md#comment-content-1129)
 2.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/is_attachment/#comment-1129)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fis_attachment%2F%23comment-1129)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fis_attachment%2F%23comment-1129)
 4. **Basic Example**
 5.     ```php
        <?php
        if ( is_attachment() ) {
        	// show adv. #1
        } else {
        	// show adv. #2
        }
        ```
    
 6. ?>
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fis_attachment%2F%3Freplytocom%3D1129%23feedback-editor-1129)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fis_attachment%2F)
before being able to contribute a note or feedback.