# Remove Usernames From CSS Classes

> Strips the author and commenter usernames WordPress adds to body and comment classes, closing a quiet way to discover login names.

- Type: PHP
- Runs: Frontend only
- Category: [Security](https://wpide.com/library/category/security/)
- Tags: security, enumeration, privacy
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/remove-usernames-from-css-classes/

## Code

```php
add_filter( 'comment_class', function ( $classes ) {
    return array_values( array_filter( $classes, function ( $class ) {
        return 0 !== strpos( $class, 'comment-author-' );
    } ) );
} );

add_filter( 'body_class', function ( $classes ) {
    if ( ! is_author() ) {
        return $classes;
    }

    $author = get_queried_object();

    if ( $author instanceof WP_User ) {
        $classes = array_diff( $classes, array( 'author-' . sanitize_html_class( $author->user_nicename, $author->ID ) ) );
    }

    return array_values( $classes );
} );
```

## Notes

Check that your theme CSS does not rely on these classes.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Remove Usernames From CSS Classes" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
