author_linkfilter-hookWP 2.1.0

Allows you to change the URL of an author's archive page.

Usage

add_filter( 'author_link', 'wp_kama_author_link_filter', 10, 3 );

/**
 * Function for `author_link` filter-hook.
 * 
 * @param string $link            The URL to the author's page.
 * @param int    $author_id       The author's ID.
 * @param string $author_nicename The author's nice name.
 *
 * @return string
 */
function wp_kama_author_link_filter( $link, $author_id, $author_nicename ){
	// filter...
	return $link;
}
$link(string)
The URL of the author's archive page.
$author_id(integer)
The ID of the author whose archive page URL is being changed.
$author_nicename(string)
The author's nice name, whose page URL is passed through the filter.

Examples

#1 Change the author archive page link

By default, WordPress generates the following author archive page link:

http://wp-test.ru/author/campusboy

Suppose you decide to display the author's posts at:

http://wp-test.ru/writer/campusboy

The following code creates such a link:

add_filter( 'author_link', 'filter_author_link', 10, 3 );

function filter_author_link( $link, $author_id, $author_nicename ) {
	return home_url( '/writer/' ) . $author_nicename;
}

However, visiting this page now results in a 404 error because WordPress does not know about this link structure. Tell it about the structure:

add_action( 'init', 'new_author_base' );
function new_author_base() {
	global $wp_rewrite;
	$wp_rewrite->author_base = 'writer';
}

After adding the code, flush the rewrite rules. To do this, simply visit the Permalinks page in the admin area.

Changelog

Since 2.1.0 Introduced.

Where the hook is called

get_author_posts_url()
author_link
wp-includes/author-template.php 413
$link = apply_filters( 'author_link', $link, $author_id, $author_nicename );

Where the hook is used in WordPress

Usage not found.