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

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);
}

扩展阅读

wp_attachment_is_image()函数位于:wp-includes/post.php

相关函数:

  • wp_attachment_is()
  • wp_check_filetype()

原创文章,作者:,如若转载,请注明出处:https://ce.771633.xyz/1889.html

Like (0)
Previous 2025年3月8日
Next 2025年3月8日

相关推荐

发表回复

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