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.

Return

true/false.

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

Usage

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

Examples

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

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

Code of wp attachment is image: wp-includes/post.php WP 5.2.2

<?php
function wp_attachment_is_image( $post = null ) {
	return wp_attachment_is( 'image', $post );
}

Related Functions

From tag: Conditional tags (all)

More from category: Images

No comments
    Hello, !     Log In . Register