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

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

author slug base

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 the 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 the title of a publicly viewable page in WordPress formatted to be used in URLs.

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

Here, green-colored text is the slug, and red-colored text is the base. That means “morshed” is the slug, and “blog” is the base. By default, WordPress uses “author” as the base. You may want to change it, as Thought Might did.

I will show you two ways to do 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.

1. With Plugin

Install and activate the Edit Author Slug plugin.

i) 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 a different author base for users with different user roles.

change author base in WordPress

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

ii) 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 the Edit User screen, scroll down to the ‘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

i) To change the author base, copy and paste the following code into 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.

Finally, go to Settings » Permalinks and click on the ‘Save Changes’ button without modifying anything.

ii) To change the author slug, copy and paste the following code into 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 the author slug.

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

Read more from Tutorial

Written by:

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

Have you written on ThoughtMight?Write Today



Leave a Comment

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