How check that there is post thumbnail feature image or not on wordpress?

On my wordpress site ,I have some post that all of them have post thumbnail, but their post thumbnail removed from host

On my wordpress site ,
I have some post that all of them have post thumbnail, but their post thumbnail removed from host and now when i want to load them on site , there is no image for loading to user ,
I want to know how can i set that if feature image is removed, show default image?
thanks

On my wordpress site ,
I have some post that all of them have post thumbnail, but their post thumbnail removed from host and now when i want to load them on site , there is no image for loading to user ,
I want to know how can i set that if feature image is removed, show default image?
thanks

Share Improve this question asked Jun 2, 2019 at 23:39 Amin ArjmandAmin Arjmand 1134 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The main problem here is what exactly was removed. If only thumbnails, then you can always regenerate them and everything should work OK.

If all files are missing, then you can check if attached file is missing using this code:

if ( file_exists( get_attached_file ( get_post_thumbnail_id( $post_id ) ) ) {
    // file exists
} else {
    // file doesn’t exist
}

You can also use wp_attachment_is_image function for that:

if ( wp_attachment_is_image ( get_post_thumbnail_id( $post_id ) ) {
    // file exists
} else {
    // file doesn’t exist
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745442477a4627892.html

相关推荐

  • How check that there is post thumbnail feature image or not on wordpress?

    On my wordpress site ,I have some post that all of them have post thumbnail, but their post thumbnail removed from host

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信