Sometimes author archive or author pages in WordPress can create issues. Author pages exposes usernames of WordPress websites users and hackers can use the usernames as a backdoor to access or break your website.
Once the author archives are indexed by search engines username or username of author becomes public and any one can know the username with a single search at search engine.
Disabling author archive or author pages can be disabled or redirected to another page by following methods
1- The .htaccess way
Simply copy and post below code your WordPress .htaccess file.
#Disable Author Pages
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} ^/?author=([0-9]*) [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/? [L,R=301,NC]
</IfModule>
Don’t forget to take a backup of .htaccess file before adding above code. If something breaks, revert the changes back to their original state
2- The PHP/Wordpress way
You can do this by using template_redirect hook. See below code example.
function oc_author_page_redirect() {
if ( is_author() ) {
wp_redirect( home_url() );
}
}
add_action( 'template_redirect', 'oc_author_page_redirect' );
You should add above code to functions.php file in active WordPress theme. This code will redirect all author pages to website homepage.
3- The Plugin way
You can use any plugin to hide Author Archives. There are different plugins available for removing author URL in WordPress Website.
You can also use Yoast SEO to hide author archive. If you have Yoast SEO Plugin installed, you should navigate to SEO-> Search appearance -> Archives and toggle settings to ‘Disabled’ for Author archive settings.
Make sure to keep a backup your files before applying above codes. If you need help with your WordPress website, you can hire our professional WordPress Web Developer by reaching us here.