wp_attachment_is()
Checks if the specified attachment is: an image, audio, or video. Conditional tag.
Used By: wp_attachment_is_image()
1 time — 0.00137 sec (very slow) | 50000 times — 11.36 sec (slow)
No Hooks.
Returns
true|false.
Usage
wp_attachment_is( $type, $post_id );
- $type(string) (required)
- Type to check. Can be: 'image', 'audio', or 'video'.
- $post_id(int/WP_Post) (required)
- ID of the attachment, the attached file. You can pass the attachment object.
Examples
#1 Check if the attached file is a picture
Let's say we got a file attached to the post and know its ID - 54. Now we need to check if it is an image:
if( wp_attachment_is( 'image', 54 ) ){
// image
}
else {
// not image
}
The same check is done by wp_attachment_is_image().
Changelog
| Since 4.2.0 | Introduced. |