wp_attachment_is()
Verifies an attachment is of a given type.
Used By: wp_attachment_is_image()
1 time — 0.00137 sec (very slow) | 50000 times — 11.36 sec (slow)
No Hooks.
Return
true|false
. True if one of the accepted types, false otherwise.
Usage
wp_attachment_is( $type, $post );
- $type(string) (required)
- Attachment type. Accepts 'image', 'audio', or 'video'.
- $post(int|WP_Post)
- Attachment ID or object.
Default: global $post
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. |