removing 'author' slug form author URL

Hello guys,

I have multisite WP install, where i've set 'news' prefix to permalink settins like /news/%postname%/.

Now the main thing.

I would like to have my authors URLS like domain.tld/user-nicename.
I am trying to solve this for like 3 hours and there is no way.

As for now i have this in my functions.php


add_action( 'init', 'custom_page_rules' );
function custom_page_rules() {
global $wp_rewrite;
$wp_rewrite->page_structure = $wp_rewrite->root . 'stranky/%pagename%';
if( 'author' == $wp_rewrite->author_base ) $wp_rewrite->author_base = '';

function author_base_rewrite_rules_function( $author_rewrite ) {

global $wpdb;
// Grab the user_nicename column
$authors = $wpdb->get_col( "SELECT user_nicename FROM {$wpdb->users}" );

// Loop through every user and create corresponding rewrite rules
foreach( $authors as $author ) {
//var_dump( $author );
$author_rewrite["({$author})/?$"] = 'index.php?author_name=$matches[1]';

// Return new rewrite rules
return $author_rewrite;
add_filter( 'author_rewrite_rules', 'author_base_rewrite_rules_function' );

function clear_author_rewrite_rules( $user_id = NULL) {
apply_filters('author_rewrite_rules' );
add_action('user_register', 'clear_author_rewrite_rules');

I am creating author programatically through wp_insert_user where i set them theirs url.
Everythings go great but when i click on author URL i've got 404.

I've installed rewrite_rules_insperctor and there is always missing rule like
(john-doe)/?$ index.php?author_name=$matches[1]

re-saving permalinks solves the problem but i need this work automatically.

Thanks for any help