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 |4 Answers
Reset to default 24The 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
版权声明:本文标题:How to remove the author pages? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742333391a2455141.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
/author/myusername
to something else using this plugin - wordpress/plugins/edit-author-slug – Tiago Peres Commented Jul 15, 2022 at 20:49