1

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

1 Answer 1

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
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.