How to set default author in WordPress

To set default author in WordPress add the following code to any code snippet plugin such as WP Code or Code Snippets

function set_default_author( $data, $postarr ) {
    // Check if the post is being created
    if ( 'auto-draft' === $postarr['post_status'] ) {
        // Set the default author ID
        $default_author_id = 2; // Replace with the user ID of the desired default author
        
        // Set the post author to the default author
        $data['post_author'] = $default_author_id;
    }
    
    return $data;
}
add_filter( 'wp_insert_post_data', 'set_default_author', 10, 2 );

To change author you can change author id. read this blog to know author id