Remove the author word from wordpress permalink

Sponsors


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.

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 perlink 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;
}

Incoming search terms:

You may like following Articles!

This entry was posted in tutorials, wordpress, wordpress api, wordpress tutorials by Wordpress API. Bookmark the permalink.

About Wordpress API

API means Application Program interface. In Wordpress API we are giving all the information about wordpress API. We worked for many wordpress plugins and themes. We have expertise in PHP, Databases, Graphic Design, Ruby on Rails, Java, Wordpress, Drupal and many CMS. We always give you the best solutions about wordpress and other related topics in This Blog. We will give you always fresh tips and tricks and techniques about wordpress in this blog.

7 thoughts on “Remove the 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.

  2. Something has gone terribly wrong with my blog after I inserted your code in my functions.php file. Now my ‘about-me’ page tries to resolve to /authoreric-evans and my /author/eric-evans tries to resolve to the same place. I need to get this fixed ASAP! Please help!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>