WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp attachment is image

Description

This function determines if a post's attachment is an image. It returns TRUE if the attachment is an image, FALSE if not. The accepted file extensions/mime types are: .jpg, .jpeg, .gif, .png.

Usage

 <?php wp_attachment_is_image$post_id ); ?> 

Parameters

$post_id
(int) (optional) Integer ID of the post.
Default: 0

Return Values

(bool) 
TRUE if the attachment is an image, FALSE if not.

Example

To check if post ID 37's attachment is an image:

<?php
  $id = 37;
  if ( wp_attachment_is_image( $id ) ) {
    echo "Post ".$id." is an image!";
  } else {
    echo "Post ".$id." is not an image.";
  }
?>

Notes

Change Log

Since: 2.1.0

Source File

wp_attachment_is_image() is located in wp-includes/post.php.

Related

See also index of Function Reference and index of Template Tags.