Last active
August 29, 2015 14:24
-
-
Save maneja81/21061a3336723c5e42da to your computer and use it in GitHub Desktop.
Remove author from WordPress Author Url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Must save permalinks from Settings >> Permalinks to get this working after implementation.