0

I maintain a WordPress site (I'm a programmer but don't have much WordPress experience), and we've noticed that Google is ending up with high-ranked links to "pages" on the WordPress site that we don't really want to be available, such as:

sitename.net/?author=2

which lists a dump of all pages written by author number 2, which were supposed to only be viewed in a certain way where they're organized and presented as intended. Is there a way to disable this feature, and/or redirect links to such things to the main site or some other relevant URL?

4
  • 1
    A quick search on this site for 'redirect_author_pages' can help, one answer that may be able to help you out or point you in the right direction is wordpress.stackexchange.com/questions/14047/… Commented Jul 8, 2015 at 0:02
  • 1
    The key points being to hook into the template_redirect hook so that you can safely redirect to another page, and within that hook you can check if the current page is an author page by calling is_author Commented Jul 8, 2015 at 0:03
  • I see how to write the condition code for a filter function as in the second link. But I don't know where to add such code, or how to get it to run at the right time. I searched up wpa_parse_query in a few places on my site, but it's in dense machine-generated scripts as far as I've seen so far. My site is based on the twenty-twelve template. Any pointers to how to correctly insert such a condition for page requests?
    – Dronz
    Commented Jul 8, 2015 at 0:41
  • 1
    Add the filter function code into the functions.php file in your twenty-twelve theme directory Commented Jul 8, 2015 at 0:46

1 Answer 1

0

Based on @czerspalace 's tips, I seem to have created a working filter for this.

I added the following function to the functions.php file in my twenty-twelve theme directory:

function redirect_author_query_to_home( $query ){
    if( is_author() ) {
        wp_redirect( home_url() );
        exit;
    }
}
add_action( 'parse_query', 'redirect_author_query_to_home' );
2

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.