[wd_asp elements=’search’ ratio=’100%’ id=1]

Stop author and category from being indexed by WordPress

31st May 2019

Admin WP

wordpress category

This code below will prevent WordPress from indexing the Author and Category.
Add this code to your functions.php file.
Check this by using screaming frog.


add_action('template_redirect', 'mikes_remove_wp_archives');

/* Remove archives */
function mikes_remove_wp_archives(){
//If we are on category or tag or date or author archive
if( is_category() || is_tag() || is_date() || is_author() ) {
global $wp_query;
wp_redirect( home_url( '/' ) );
// $wp_query->set_404(); //set to 404 not found page
}
}

You can also do this from the .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/wp-admin [NC]
RewriteCond %{QUERY_STRING} author=\d
RewriteRule ^ /? [L,R=301]

You can test this by visiting www.mywebsite.co.uk?author=1
After applying a script visit the url of your website and see if it still appears.