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.