要仅编辑与作者关联的链接,请在函数中。主题的php:
add_filter( \'author_link\', \'new_author_link\', 10, 1 );
function new_author_link( $link ) {
$link = \'http://newlink.com/\'; //set this however you wish
return $link; //after you\'ve set $link, return it to the filter
}
如果你想把每个作者的链接设置为一个同名的现有wp页面(
untested example):
add_filter( \'author_link\', \'new_author_link\', 10, 3 );
function new_author_link( $link, $author_id, $author_nicename ) {
$page = get_page_by_path( $author_nicename );
if ($page) {
$page = $page->ID;
$link = get_permalink( $page );
}
else {
$link = \'\'; //some default value perhaps
}
return $link;
}
更多来自WP Codex on
Filtering the Author更多来自WP Codex onFilters in general.
更新示例:如果您试图将所有作者链接重定向到home_url( \'link\' )
add_filter( \'author_link\', \'new_author_link\', 10, 1 );
function new_author_link( $link ) {
$link = home_url( \'link\' ); //set this however you wish
return $link; //after you\'ve set $link, return it to the filter
}
如果您试图实现其他一些有条件的If/else:
add_filter( \'author_link\', \'new_author_link\', 10, 1 );
function new_author_link( $link, $author_id, $author_nicename ) {
//send author with id one to home link
if ($author_id == \'1\') {
$link = home_url( \'link\' ); //set this however you wish
}
//send all other authors to some other link
else {
$link = \'http://sitename.com/some-other-url/\';
}
return $link; //after you\'ve set $link, return it to the filter
}