← Back to All Snippets

Disable Author Enumeration Scans (?author=1) in WordPress

⚡ Target: functions.php 🔒 Tested: WP 6.6+ / PHP 8.2+ 💻 Lang: PHP
PHP (functions.php)
add_action( 'template_redirect', function() {
    if ( is_author() || ( isset( $_GET['author'] ) && is_numeric( $_GET['author'] ) ) ) {
        wp_safe_redirect( home_url(), 301 );
        exit;
    }
} );

Attackers and botnets use URL parameters like /?author=1 to reveal administrative usernames. This snippet intercepts query parameters and safely redirects or returns a 404 header.

← Back to All Snippets Explore Dev Tools →