WordPress at a glance

wp_attachment_is_image() WP 2.1.0

Determines whether the specified post is WordPress attachment image. A conditional tag.

Works based on: wp_attachment_is()
1 time = 0.000291s = fast | 50000 times = 0.44s = very fast | PHP 7.0.14, WP 4.7

No Hooks.



  • true, if the post MIME type is: jpg, jpeg, jpe, gif, png.
  • false in any other case.


wp_attachment_is_image( $post );
Attachment (post) ID or object.
Default: null (global $post)


#1 Check whether an attachment (a post) with ID 37 is an image

$id = 37;
if( wp_attachment_is_image( $id ) )
	echo "Post with ID $id — is an image!";
	echo "Post with ID $id is not an image.";

Список изменений

С версии 2.1.0 Введена.
С версии 4.2.0 Modified into wrapper for wp_attachment_is() and allowed WP_Post object to be passed.

Code of wp_attachment_is_image() WP 5.5.1

function wp_attachment_is_image( $post = null ) {
	return wp_attachment_is( 'image', $post );

Related Functions

From tag: Conditional tags (all)

More from category: Images

vladlu 100vlad.lu
Editors: kama 100
No comments
    Log In . Register