我们可以尝试通过comment_form_logged_in 过滤器,其中HTML默认构造为:
\'<p class="logged-in-as">\' . sprintf(
/* translators: 1: edit user link, 2: accessibility text, 3: user name, 4: logout URL */
__( \'<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>\' ),
get_edit_user_link(),
/* translators: %s: user name */
esc_attr( sprintf( __( \'Logged in as %s. Edit your profile.\' ), $user_identity ) ),
$user_identity,
wp_logout_url( apply_filters( \'the_permalink\', get_permalink( $post_id ) ) )
) . \'</p>\'
但由于它相当复杂,我们可能会失去翻译,在重建它时,我们可能会尝试将其替换为(一次),例如:
add_filter( \'comment_form_logged_in\', function( $html, $commenter, $user_identity )
{
return preg_replace( \'#<a href="[^"]*" aria-label="[^"]*">([^<]*)</a>#\', \'$1\', $html, 1);
}, 10, 3 );
或者使用DomDocument方法。参见示例。
here.
请注意,如果核心中的翻译字符串发生变化,则可能需要进行调整!