How to Stop indexing author’s profile

Author/Username

When we publish a post, the profile of the user who has published the post by WordPress automatically gets indexed in the sitemap, due to which sometimes the URL of the main post is not indexed but the author’s link appears in the search engine, due to which The visitors coming to the website are not able to get the main post.

How to prevent the author’s profile from being indexed?

By pasting the following code into the theme’s functions.php, the url created in the sitemap can be prevented from indexing by removing

//sitemap
add_filter(
'wp_sitemaps_add_provider',
function( $provider, $name ) {
if ( 'users' === $name ) {
return false;
}
return $provider;
},
10,
2
);

Then SAVE functions.php file after paste this code.