I've got an issue with author's template. It works great and displays authors profiles as expected, but the issue is that you can see non-authors profiles also (contributors / subscribers, basically all registered users, including and admin) simply by substituting username in URL (www.mysite.com/author/subscribername).

Is there any simple way to fix it and show 'authors' profiles only and return 'page not found' for others?

In advance of your support, thank you.

Update: Solution I've applied and will use (unless someone will advise how to amend the initial query). This returns proper 'page not found' page, including 'page not found' page title:

function tb_author_role_template( $templates='' )
    global $wp_query;

    $author = get_queried_object();
    $role = $author->roles[0];

    if($role == 'author') 
    } else { // error if not author
        header( 'HTTP/1.0 404 Not Found' );
        $templates = locate_template(array("404.php",$templates),false);
        $wp_query->is_404 = true;
    return $templates;
add_filter( 'author_template', 'tb_author_role_template' );

You're going to want to use the author_template filter to process this. Just to clarify, the filter's "author" means all users, it appears. I'm not sure why. This will be called while the backend is deciding which template page to use when showing a user's profile on your site. You need to add an author-editor.php file and then filter to it if the user matches your criteria.

function author_role_template( $templates='' )
    $author = get_queried_object();

    if($role == 'author') {
    } else { // error if not author
    return $templates;
add_filter( 'author_template', 'author_role_template' );

Source: Codex -- Template Hierarchy

NOTE: You'll need to verify that roll returns true for this. I'm not 100% on it the comparison of the roll to the string.

  • Thanks for your answer and solution. It works alright, but page title still says "welcome to non-author profile"... so basically WP think that it shows user profile, just the template is 404. I appreciate that it's possible to change page title as well, but I'm wondering whether it's possible to amend the initial query (SELECT * FROM wp_users WHERE user_nicename = '$author_name') I believe that would be the proper solution for my issue... – Tomas Jan 23 '13 at 8:23

Here's a possible approach, to be implemented in author.php:

    global $wp_query;
    $roles = $wp_query->queried_object->roles;
    if( ! $roles[0] == 'author' ) {
        echo '<p>Nothing here!</p>';
    } else { 
        // show author archive

If you do not wish to edit templates, take a look at the template_redirect function


edit htaccess try this:

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{HTTP_USER_AGENT} !Google [NC]
 RewriteRule ^author/?([_0-9a-z-]+)?/?$ http://misite.com [R=302,NC,L]
  • Could you summarize what the code does, please? – s_ha_dum Jan 22 '13 at 22:33
  • the code performs a redirect to the homesite if you try to enter paths www.misite.com/author/........ but if you are a googlebot list it – funji Jan 22 '13 at 22:37

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.