WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to use a custom value to be used in the author posts URL instead of the user_nicename which defaults to user_login in the pretty permalink structure. So far I managed to do that but now the new URL /author/custom_user_nicename generate a 404 error while the old one /author/user_login still works. The code I used in theme functions.php file:

add_filter('author_link', 'update_author_link',10,2);
function update_author_link($link,$author_id) {
    if (FALSE === strpos($link, '?author=')) { // only if pretty permalinks used
        $position = strrpos($link, '/');
        if (strlen($link) == $position + 1) { // check and remove trailing slash
            $link = untrailingslashit($link);
            $position = strrpos($link, '/');
        $link = substr($link, 0, $position+1);
        $link = $link . get_the_author_meta('custom_author_nicename', $author_id);
        return user_trailingslashit($link);
    return $link;

I tried to flush the rewrite rules by going to settings -> permalinks and save but that did work as well. do I need to update or modify anything else for the new author URL to work? Thanks.

share|improve this question
up vote 0 down vote accepted

You'll need to add a rewrite rule as well as the filter you have written. At the moment your filter only changes what is output when the author_link function is called, not WordPress' permalink structure.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.