How to Change the Author Slug URL Base in WordPress

WPTurbo » Snippets » How to Change the Author Slug URL Base in WordPress
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

Are you looking to customize the URL structure for author pages on your WordPress website? By default, WordPress uses the "author" slug followed by the user’s ID or username in the URL. However, if you want to change the default author slug URL base to something more unique or personalized, you’re in the right place. In this article, we will guide you through the steps to change the author slug URL base in WordPress, allowing you to create a more tailored and SEO-friendly URL structure for your author pages. Let’s dive in!

					function wpturbo_change_author_slug_url_base( $base ) {
    $base = 'team';
    return $base;
}
add_filter( 'author_rewrite_base', 'wpturbo_change_author_slug_url_base' );
				

The code snippet above demonstrates how to change the author slug URL base in WordPress. By default, WordPress uses the "author" slug in the URL structure to represent author pages, such as domain.com/author/username. However, you may want to customize this and use a different slug, such as "team".

To achieve this customization, we need to create a function called wpturbo_change_author_slug_url_base that accepts the current base as an argument and returns the new base. In our case, we will set the new base to be "team".

function wpturbo_change_author_slug_url_base( $base ) {
    $base = 'team';
    return $base;
}

Inside the function, we assign the value "team" to the $base variable. This sets the new slug that we want to use in the URL structure for author pages.

Next, we need to hook this function into the author_rewrite_base filter using the add_filter function. This filter allows us to modify the author slug URL base before it is used in generating the author page URLs.

add_filter( 'author_rewrite_base', 'wpturbo_change_author_slug_url_base' );

By adding this hook, our function wpturbo_change_author_slug_url_base will be called whenever WordPress generates the author slug URL base. It will override the default "author" base and replace it with our new base "team".

Once you implement this code snippet in your WordPress site’s functions.php file or in a custom plugin, the author page URLs will use the new slug "team" instead of "author". For example, the author page URL for the username "john" will be domain.com/team/john.

Register an account to save your snippets or go Pro to get more features.