WordPress根据附件ID判断附件是否是图像函数:wp_attachment_is_image

2022/07/13

WordPress函数wp_attachment_is_image根据附件的ID判断该附件是否是图像,如果想要通过文件路径来判断,则可以使用wp_check_filetype函数。

另外,需要注意的是,该函数判断文件类型是以文件的后缀来判断的。

wp_attachment_is_image( int|WP_Post $post = null )

本文涉及的内容包括:

函数参数

$post

整数或对象

附件的ID或包含附件信息的对象

函数使用示例

$id = 37;
if(wp_attachment_is_image($id)) {
    printf('Post %d is an image!', $id);
} else {
    printf('Post %d is not an image.', $id);
}

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注