the_author_posts_link
Allows you to change the HTML of the link to the author's post archive page.
Usage
add_filter( 'the_author_posts_link', 'wp_kama_the_author_posts_link_filter', 10, 3 );
/**
* Function for `the_author_posts_link` filter-hook.
*
* @param string $link HTML link.
* @param string $author Author's display name.
* @param string $title Text originally used for a title attribute.
*
* @return string
*/
function wp_kama_the_author_posts_link_filter( $link, $author, $title ){
// filter...
return $link;
}
- $link(string)
- The link HTML.
Examples
#1 Change the anchor text of the author post archive link
The code almost exactly reproduces the code of get_the_author_posts_link():
add_filter( 'the_author_posts_link', 'filter_the_author_posts_link' );
function filter_the_author_posts_link( $link ) {
global $authordata;
if ( ! is_object( $authordata ) ) {
return;
}
$link = sprintf( '<a href="%1$s" title="%2$s" rel="author">Other posts by the author: %3$s</a>',
esc_url( get_author_posts_url( $authordata->ID, $authordata->user_nicename ) ),
esc_attr( sprintf( __( 'Posts by %s' ), get_the_author() ) ),
get_the_author()
);
return $link;
}Changelog
| Since 2.9.0 | Introduced. |
| Since 7.0.0 | Added $author and $title parameters. |
Where the hook is called
the_author_posts_link
wp-includes/author-template.php 355
return apply_filters( 'the_author_posts_link', $link, $author, $title );