WordPress函数:wp_attachment_is_image 判断是否是图片附件

追格官方小助手/ 2022年07月19日/ WordPress/ 浏览 1022

在WordPress中,wp_attachment_is_image 用来判断文章是否是附件。可以接受文章ID或WP_Post类型对象。


函数源码:


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


可以看到源码直接调用了 wp_attachment_is,是一个语法糖函数。


使用举例:


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

发表评论

暂无评论,抢个沙发...

客服 工单