Note: This will not retroactively assign the default featured image to posts. This applies to posts you create going forward.
Adjust Line 9, 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 );