Note: This solution applies to posts you create going forward. It does not retroactively assign the default featured image to posts you’ve already published.
Adjust Line 7, adding the full URL of the image you want to assign as the default featured image.
PHP
function mytheme_set_default_thumbnail( $post ) {
if ( $post->post_type != 'post' ) {
return;
}
if ( !has_post_thumbnail( $post->ID ) ) {
$thumbnail_url = 'https://domain.com/wp-content/uploads/image-file-name';
$thumbnail_id = attachment_url_to_postid( $thumbnail_url );
set_post_thumbnail( $post->ID, $thumbnail_id );
}
}
add_action( 'rest_after_insert_post', 'mytheme_set_default_thumbnail', 10, 3 );