0

I have disabled the author pages on my WordPress blog using the Yoast SEO plugin, but I saw that when I click the author name, it just redirects me to the homepage. Can I change the URL myblog.com/author/me directly to myblog.com, without a 301 redirect? Thanks!

1

Disabling the author pages is a 'good thing'. A 'bad actor' can enumerate your users, or even get your admin user (which is user id 1) with a simple query on any page. So redirecting author requests is a good idea - and a good security measure. (As is never having a user called 'admin', especially if it has admin privileges.)

For instance, an attacker could use the xmlprc.prg page to post multiple requests to any page. They could look through x number of author id's and get a list of the login names of all the user ids. Then use that list to try to get into the admin pages.

I suspect that the Yoast plugin is redirecting author requests. The code to redirect author requests to the home page will look like this:

function wp_redirect_if_author_query() {

    $is_author_set = get_query_var( 'author', '' );
    if ( $is_author_set != '' && !is_admin()) {
        wp_redirect( home_url(), 301 );     // send them somewhere else
        exit;
    }
}
add_action( 'template_redirect', 'wp_redirect_if_author_query' );

Put a variation of this code (with the redirect you want to have) in your Child Theme's functions.php file. Or in a simple plugin. (I have a customized personal plugin where I do all sorts of standard settings, including those related to security.) You might need to give a higher priority to the add_action (the optional third parameter, which defaults to 10) to override what the Yoast plugin is doing.

| improve this answer | |
  • This thing is already done by Yoast. My question is if you can do it without 301 redirects (because, in SEO checkers, I saw it's not a good thing to have too many 301 redirects in the homepage). I mean, when you click on the author name, it should be pointing to the homepage directly. – Iulian Oleniuc Jun 27 '18 at 16:45
  • Yes you can. Just give your add_action a higher priority than what Yoast is doing. You might have to experiment with priority values. And if you are concerned about a 301 redirect on the home page, then add a check for is_home() in the 'if' statement. Although I don't think 301's on the home page are bad; in fact, they are the best way. See moz.com/learn/seo/redirection . – Rick Hellewell Jun 27 '18 at 18:03
  • Hmm, so after I do what you said, if I right click on the author name, and copy the link, it should be the link to the homepage? I have tried it with and without is_home(), and with higher and lower priorities, but none of them worked. – Iulian Oleniuc Jun 27 '18 at 18:29
  • If your link is like example.com/?author=1 , then the function should redirect to the value specified by wp_redirect. If you don't specify the 301, then a 302 is sent. If your link is something else, then use that value in get_query_var. Post your URL, but sanitize it with 'example.com'. – Rick Hellewell Jun 27 '18 at 18:51
  • I have finally found that my question was answered here. :) The code in the first post works for me. Thank you anyway! – Iulian Oleniuc Jun 27 '18 at 19:06
0

In Yoast just select:

Author Archives - enabled Show in search results - disabled

Better than mucking around with code.

| 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.