Remove the CSS classes that reveal each author's login name in comments and on author archive pages.
// Comments get a class like "comment-author-jane-admin".
add_filter( 'comment_class', function ( array $classes ): array {
return array_values( array_filter( $classes, fn ( $class ) => ! str_starts_with( $class, 'comment-author-' ) ) );
} );
// Author archives get a class like "author-jane-admin". Keep "author" and "author-{id}".
add_filter( 'body_class', function ( array $classes ): array {
return array_values( array_filter( $classes, fn ( $class ) => ! preg_match( '/^author-(?!\d+$)/', $class ) ) );
} );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
WordPress adds the comment author’s nicename to each comment’s CSS classes, and the author’s nicename to the body class on author pages. Nicenames are often the same as login names, so this publishes usernames in your HTML.
The comment_class filter removes every class starting with comment-author-. WordPress’s bypostauthor class, which themes use to highlight the post author’s replies, is kept.
The body_class filter removes author-{nicename} from author archives while keeping author and the numeric author-{id} class.
View the source of a post with comments and search for comment-author-. It shouldn’t appear.