WordPress Code Snippets

A fresh mix of code snippets and tutorials

WordPress Disable Author Archives

282

This WordPress snippet disables all author-archive views. This may be useful to prevent user enumeration scans, and also may help to minimize duplicate content (for SEO purposes).

To disable all author archives, add the following code snippet to your theme’s functions.php file:

// disable author archives
function shapeSpace_disable_author_archives() {
	
	if (is_author()) {
		
		global $wp_query;
		$wp_query->set_404();
		status_header(404);
		
	} else {
		
		redirect_canonical();
		
	}
	
}
remove_filter('template_redirect', 'redirect_canonical');
add_action('template_redirect', 'shapeSpace_disable_author_archives');

Once in place, this code checks if the request is for an author archive, and if so, redirects as a 404 (Not Found) request. No editing is required, but you may want to tweak the redirect/response to something more user-friendly. For more information, check out my tutorial on stopping user-enumeration scans in WordPress.

Learn more

WordPress Themes In Depth


Show Support

Like our new Facebook Page to show support!