xxxxxxxxxx
//default
$image_url = wp_get_attachment_url(1234);
// change if post have feature image
if (has_post_thumbnail($recent_post['ID'])) {
$image_url = wp_get_attachment_url(get_post_thumbnail_id($recent_post['ID']), '');
}
xxxxxxxxxx
<?php if(has_post_thumbnail()){
the_post_thumnbail('cstm_name', array( 'class' => 'class1 class2' ))
} else { ?>
<img class="card-img-top" src="http://placehold.it/750x300" alt="Card image cap" class="img-responsive">
<?php } ?>
xxxxxxxxxx
$url = "http://url-of-the-image.jpg";
$post_id = [post id]
$desc = "image description";
$image = media_sideload_image( $url, $post_id, $desc,'id' );
set_post_thumbnail( $post_id, $image );