If you want to remove author base in WordPress? Use the below WordPress code to remove author base from URL.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | add_filter('author_rewrite_rules', 'no_author_base_rewrite_rules'); function no_author_base_rewrite_rules($author_rewrite) { global $wpdb; $author_rewrite = array(); $authors = $wpdb->get_results("SELECT user_nicename AS nicename from $wpdb->users"); foreach($authors as $author) { $author_rewrite["({$author->nicename})/page/?([0-9]+)/?$"] = 'index.php?author_name=$matches[1]&paged=$matches[2]'; $author_rewrite["({$author->nicename})/?$"] = 'index.php?author_name=$matches[1]'; } return $author_rewrite; } if( !is_admin() ) { add_action('init', 'author_rewrite_so_22115103'); } function author_rewrite_so_22115103() { global $wp_rewrite; if( 'author' == $wp_rewrite->author_base ) $wp_rewrite->author_base = null; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.