admin管理员组

文章数量:1334295

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


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.

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

http://www.domain/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.

Share Improve this question asked Aug 22, 2017 at 4:11 1.21 gigawatts1.21 gigawatts 1,0003 gold badges13 silver badges34 bronze badges 5
  • why don;t you remove the author name links from posts? – inarilo Commented Aug 22, 2017 at 7:07
  • I follow the link to the author page listed and it says no posts. So I don't know where the link is coming from. – 1.21 gigawatts Commented Aug 22, 2017 at 9:29
  • blog.futtta.be/2015/03/03/… – inarilo Commented Aug 22, 2017 at 22:07
  • 1 I know you're not looking for a plugin, but here is one for those who are looking: wordpress/plugins/disable-author-archives – Flimm Commented Aug 29, 2019 at 16:48
  • 1 You can also change the /author/myusername to something else using this plugin - wordpress/plugins/edit-author-slug – Tiago Peres Commented Jul 15, 2022 at 20:49
Add a comment  | 

4 Answers 4

Reset to default 24

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/reference/functions/wp_redirect/

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

  • WordPress template hierarchy: https://developer.wordpress/themes/basics/template-hierarchy/
  • PHP header function: https://www.php/manual/en/function.header.php
  • WordPress wp_safe_redirect function: https://codex.wordpress/Function_Reference/wp_safe_redirect

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

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

本文标签: How to remove the author pages