Quantcast
Channel: BIOSTALL » PHP
Viewing all articles
Browse latest Browse all 57

Change Author Base URL in WordPress Permalinks

$
0
0

By default when viewing a user’s profile page on the front end of a WordPress site, the URL will looks something like so:

http://mysite.com/author/joe-bloggs

The base URL will be ‘author’ followed by the users name. This is fine and works if users in the system are authors and post news articles etc.

In a site I was recently working on, ‘Users’ had a different meaning in that they are members that register and create a public profile. As a result, the term ‘author’ wasn’t quite right so I wanted to change the permalinks to reflect this.

The Solution

Fortunately the solution is a simple one and involved the following steps:

1. Add the following to the theme’s functions.php file:

add_action('init','change_author_permalinks');
function change_author_permalinks()
{
    global $wp_rewrite;
    $wp_rewrite->author_base = 'member'; // Change 'member' to be the base URL you wish to use
    $wp_rewrite->author_structure = '/' . $wp_rewrite->author_base. '/%author%';
}

2. Within WordPress navigate to ‘Settings > Permalinks‘ and just save the page without making any changes. This will force WordPress to flush the rewrite rules.

Now when someone views this user on the front end their profile URL will be like so:

http://mysite.com/member/joe-bloggs

Note: You should still use the author.php template to style the page. This won’t change to member.php, or whatever you set the base URL as.


Viewing all articles
Browse latest Browse all 57

Latest Images

Trending Articles



Latest Images