author slug base

How to Change Author URL Slug and Base with or without Plugin

WordPress has permalink settings. WordPress offers you the ability to create a custom URL structure for your permalinks and archives. Custom URL structures can improve the aesthetics, usability, and forward-compatibility of your links. A number of tags are available, and there are some examples in permalink settings.

However, there is no option for you to customize the author URL. In this article, I will show you how you can easily change the author URL slug and base in WordPress.

What is a URL Slug and URL Base?

In WordPress terminology, a slug is a title of a publicly viewable page in WordPress formatted to be used in URLs.

My author url for this site is: https://weusewp.com/author/morshed/

Here orange colored text is the slug and green colored text is the base. That means “morshed” is the slug and “author” is the base. By default, WordPress uses “author” as base. You may want to change it as Thought Might did. There my author url is https://thoughtmight.com/blog/morshed/

I will show you two ways to that.

  • With Plugin
  • Without Plugin

I prefer the without plugin solution and you should too as no one should use a third party plugin if it can be done with some lines of code. See how WP User Avatar Plugin Becomes Something else leaving users frustrated.

1. With Plugin

Install and activate the Edit Author Slug plugin.

To change the author base, go to the Settings » Edit Author Slug page. Here you will see an option to change the author base and even choose different author base for users with different user roles.

change author base in WordPress

Once you are finished, click on the save changes button.

To change the author slug, go to Users » All Users page. Next, click on the ‘Edit’ link below a username.

edit user in WordPress

From Edit User screen, scroll down to ‘Edit Author Slug’ section, and you will see a number of choices that you can use as author slug. You can even enter a custom slug.

edit author slug in WordPress

Don’t forget to click on the ‘Update User’ button.

2. Without Plugin

To change the author base, copy and paste following code to your theme’s functions.php file.

function new_author_base() {
    global $wp_rewrite;
    $myauthor_base = 'writer';
    $wp_rewrite->author_base = $myauthor_base;
}
add_action('init', 'new_author_base');

Change ‘writer‘ according to your need. That’s it. These few lines of code will change the author base all over your site.

To change the author slug, copy and paste following code to your theme’s functions.php file.

if (current_user_can('manage_options')) {
function lwp_2629_user_edit_ob_start() {ob_start();}
add_action( 'personal_options', 'lwp_2629_user_edit_ob_start' );
function lwp_2629_insert_nicename_input( $user ) {
    $content = ob_get_clean();
    $regex = '/<tr(.*)class="(.*)\buser-user-login-wrap\b(.*)"(.*)>([\s\S]*?)<\/tr>/';
    $nicename_row = sprintf(
        '<tr class="user-user-nicename-wrap"><th><label for="user_nicename">%1$s</label></th><td><input type="text" name="user_nicename" id="user_nicename" value="%2$s" class="regular-text" />' . "\n" . '<span class="description">%3$s</span></td></tr>',
        esc_html__( 'Nicename' ),
        esc_attr( $user->user_nicename ),
        esc_html__( 'Must be unique.' )
    );
    echo preg_replace( $regex, '\0' . $nicename_row, $content );
}
add_action( 'show_user_profile', 'lwp_2629_insert_nicename_input' );
add_action( 'edit_user_profile', 'lwp_2629_insert_nicename_input' );
function lwp_2629_profile_update( $errors, $update, $user ) {
    if ( !$update ) return;
    if ( empty( $_POST['user_nicename'] ) ) {
        $errors->add(
            'empty_nicename',
            sprintf(
                '<strong>%1$s</strong>: %2$s',
                esc_html__( 'Error' ),
                esc_html__( 'Please enter a Nicename.' )
            ),
            array( 'form-field' => 'user_nicename' )
        );
    } else {
        $user->user_nicename = $_POST['user_nicename'];
    }
}
add_action( 'user_profile_update_errors', 'lwp_2629_profile_update', 10, 3 );
}

From Users » All Users page, click on the ‘Edit’ link below a username. You will find a “Nicename” section. You can edit the slug here.

Nicename in WordPress

Click on the ‘Update User’ button after editing author slug.

Comment below to let me know if it works for you or not.

Spread the love

A teacher by profession, a traveler by passion and a netizen by choice.

Morshed Alam

You use WordPress! Why don't we share our experiences. It may be a tutorial, tips, tricks, tweaks or about security, performance or WordPress news. Write Today

Leave a Comment

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