26

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.

5

4 Answers 4

22

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/

4
  • 3
    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, 2019 at 20:26
  • This is not a good solution for hiding author's pages. If you guess author's login, you will be redirected, but if you enter non-existing author's slug, you will get a 404 error. The right approach should redirect or gives 404 in all cases.
    – Qrzysio
    Sep 18, 2022 at 20:35
  • 1
    Why global $wp_query; ?
    – Ronald
    Sep 14, 2023 at 1:36
  • For the shortlink request /?author=1to be handled the same way, the add_action priority should be set lower than the default 10. So it will be ran before the redirect_canonical default hook and so won't be skipped by it. Without it, such a shortlink will leak the author name through the redirection to /author/authorname (which will then be redirected to the home for the code I'm commenting).
    – challet
    Apr 21 at 14:22
11

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: /");
die(); // avoid further PHP processing
//That's all folks

The die() part is to avoid that anyone using a client which does NOT follow the redirect header sees the content of the page since WP would continue building the original author page and send its response to the client requesting it.


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

6

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'));
    }
}
3

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);
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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