您可以使用get_current_user_id(), get_the_author_meta(\'ID\'), 和get_edit_user_link() 功能。以下面的代码段为例:
if( get_current_user_id() === get_the_author_meta(\'ID\') ){
printf( \'<a href="%s">Edit Profile</a>\', get_edit_user_link() );
}
get_current_user_id() 将返回
int(0) 如果没有人登录,或当前用户的整数ID。这有效地消除了
is_user_logged_in().
get_the_author_meta(\'ID\') 将返回string(0) "" 如果没有页面作者(例如在主页上),或者如果有作者,则为作者的整数ID,例如在WordPress作者存档页面上。
您还可以添加is_user_logged_in(), 但正如我上面提到的,我认为这有点多余,因为get_current_user_id() 基本上为您解决了这一问题:
if( is_user_logged_in() && ( get_current_user_id() === get_the_author_meta(\'ID\') ) ){
printf( \'<a href="%s">Edit Profile</a>\', get_edit_user_link() );
}