The author_link WordPress PHP filter allows you to modify the URL to the author’s page.
Usage
add_filter('author_link', 'modify_author_link', 10, 3); function modify_author_link($link, $author_id, $author_nicename) { // your custom code here return $link; }
Parameters
$link
(string): The URL to the author’s page.$author_id
(int): The author’s ID.$author_nicename
(string): The author’s nice name.
More information
See WordPress Developer Resources: author_link
Examples
Add a custom prefix to the author URL
This code adds a custom prefix to the author URL.
function add_custom_prefix_to_author_link($link, $author_id, $author_nicename) { return home_url('/custom-prefix/' . $author_nicename); } add_filter('author_link', 'add_custom_prefix_to_author_link', 10, 3);
Redirect author URL to a custom page
This code redirects the author URL to a custom page.
function redirect_author_to_custom_page($link, $author_id, $author_nicename) { return home_url('/custom-page/' . $author_id); } add_filter('author_link', 'redirect_author_to_custom_page', 10, 3);
Add UTM parameters to author URL
This code adds UTM parameters to the author URL for tracking.
function add_utm_to_author_link($link, $author_id, $author_nicename) { return $link . '?utm_source=author&utm_medium=link&utm_campaign=author_' . $author_id; } add_filter('author_link', 'add_utm_to_author_link', 10, 3);
Remove author URL and replace with a hashtag
This code removes the author URL and replaces it with a hashtag.
function remove_author_link($link, $author_id, $author_nicename) { return '#'; } add_filter('author_link', 'remove_author_link', 10, 3);
Change author URL to a social media profile
This code changes the author URL to their social media profile.
function change_author_link_to_social_profile($link, $author_id, $author_nicename) { $twitter_url = get_user_meta($author_id, 'twitter_url', true); if (!empty($twitter_url)) { return $twitter_url; } return $link; } add_filter('author_link', 'change_author_link_to_social_profile', 10, 3);