Security PHP Beginner

Disable Author Archives

Redirect author archive pages to the homepage and stop themes linking to them, which hides author usernames.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 10 lines
// Send /author/name/ and ?author=1 to the homepage.
add_action( 'template_redirect', function (): void {
	if ( is_author() ) {
		wp_safe_redirect( home_url( '/' ), 301 );
		exit;
	}
} );

// Make author links point to the homepage too.
add_filter( 'author_link', fn () => home_url( '/' ) );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

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.

Author archives live at /author/username/, which publishes your login names. On single-author sites they also duplicate the blog. This snippet turns them off.

How it works

On template_redirect, any author archive, whether reached by pretty URL or ?author=1, is redirected to the homepage with a permanent 301. The author_link filter changes the links themes print next to posts so visitors and crawlers stop finding the archives.

Things to watch

  • Multi-author sites often want author pages. In that case, use the user enumeration snippet instead, which only blocks the ?author= trick.
  • SEO plugins can also disable author archives in their settings.

How to test it

Visit yoursite.com/?author=1. You should land on the homepage.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only