Remove author word from wordpress permalink

Remove author word from wordpress permalink

In wordpress some people wants to create the community site and they want to create uniqe url for each user. In that time you need to remove the author word from wordpress permalink. Normally when we want to see the author URL then you can see URL as follows.

Remove author word from wordpress permalink

Co-Authors Plus Remove author word from wordpress permalink
Co-Authors Plus Remove author word from wordpress permalink

http://website.com/author/username/

If you can want to change the url to following

http://website.com/username

then you just need to edit only .htaccess file. Put following line in that file

RewriteRule ^author/(.+)$ http://www.yourblog.com/$1 [R=301,L] // change yourblog to website name 

If you dont want to change the .htaccess file and still want to change the permalink structure then open the functions.php file from you wordpress theme folder.

add_filter('author_link', 'no_author_base', 1000, 2);
function no_author_base($link, $author_id) {
    $link_base = trailingslashit(get_option('home'));
    $link = preg_replace("|^{$link_base}author/|", '', $link);
    return $link_base . $link;
}
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;
}

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

3 thoughts on “Remove author word from wordpress permalink”

  1. How do i change it to where the users nickname is showing in the permalink instead of the login name? this is mainly for security purposes. your code word perfectly anf thanks for hack.

Leave a Reply

Your email address will not be published.