12

I submitted my site to Google and now the author page is showing up in the search results.

http://www.domain.com/author/myusername

How do I prevent my and others author names from showing up in search results?

It would be best to disable completely the path "/author/" all together because it's not a blog but a product site (it only has pages).

I did a search earlier and saw that there are plugins to do this but I'd rather not install a plugin (sometimes they are not updated) if there is another way but will if I have to.

I also searched through the source code of the pages and did not see any links to the author page.

11

The above answer is good, but if redirecting to home page, it should specify a 301 status and exit after.

add_action('template_redirect', 'my_custom_disable_author_page');

function my_custom_disable_author_page() {
    global $wp_query;

    if ( is_author() ) {
        // Redirect to homepage, set status to 301 permenant redirect. 
        // Function defaults to 302 temporary redirect. 
        wp_redirect(get_option('home'), 301); 
        exit; 
    }
}

wp_redirect() documentation https://developer.wordpress.org/reference/functions/wp_redirect/

|improve this answer|||||
  • 1
    I currently use Yoast SEO Plugin to remove author pages. Just change the option to not scan/index that taxonomy and you'll be good to go. No code required. – David Hobs Dec 17 '19 at 20:26
4

You can also add the redirect to the author template directly. In your WordPress theme, edit the author.php file to redirect users to your homepage. If your theme doesn't have a template for author pages, create a file named author.php.

author.php: (Using php header function)

<?php
//Redirect author pages to the homepage
header("HTTP/1.1 301 Moved Permanently");
header("Location: /");
//That's all folks

UPDATE: WordPress has a couple of built in functions to handle redirects: wp_redirect() and wp_safe_redirect(). wp_redirect() accepts a string as the redirect location and an integer as the redirect type (302 is the default). wp_safe_redirect() is the same as wp_redirect() except that it makes sure that the redirect location is found in a list of allowed hosts.

author.php: (Using WordPress wp_safe_redirect function)

<?php
//Redirect author pages to the homepage with WordPress redirect function
wp_safe_redirect( get_home_url(), 301 );
exit;
//That's all folks

More information

|improve this answer|||||
2

You can disable the access to author pages by adding this snippet to functions.php:

// Disable access to author page
add_action('template_redirect', 'my_custom_disable_author_page');

function my_custom_disable_author_page() {
    global $wp_query;

    if ( is_author() ) {
        $wp_query->set_404();
        status_header(404);
        // Redirect to homepage
        // wp_redirect(get_option('home'));
    }
}
|improve this answer|||||
2

You can disable the access to author pages if you add the following code in functions.php: file

add_action('template_redirect', 'my_custom_disable_author_page');

    function my_custom_disable_author_page() {
        global $wp_query;
        if ( is_author() ) {
            $wp_query->set_404();
            status_header(404);
        }
    }
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.