Disable Author Pages in WordPress

Disable Author Page

WordPress author pages offer a practical way to display all posts from a specific author. However, some website owners may find them unnecessary or inconsistent with their site’s design. In this extensive tutorial, we’ll guide you step-by-step on how to disable author pages and redirect visitors to the homepage seamlessly.

Step 1: Access the functions.php File

Kick-start the process by locating and opening the functions.php file within your WordPress theme folder. Here’s how:

  1. Log in to your WordPress Dashboard.
  2. Go to Appearance > Theme Editor, opening the Theme Editor page.
  3. Locate the functions.php file in the list of theme files on the right-hand side and click to open it.

Step 2: Add Custom Code

To effectively disable author pages and redirect visitors to your homepage, insert the following code snippet at the end of the functions.php file:

/**
 * Disables author pages and redirects visitors to homepage.
 */
function disable_author_pages() {
    global $wp_query;

    // Check if the current page being viewed is an author page.
    if ( is_author() ) {
        // Redirect visitor to the homepage.
        wp_redirect( get_bloginfo( 'wpurl' ), 301 );
        exit;
    }
}

// Add the 'disable_author_pages' function to the 'template_redirect' action.
// The priority is set to 1 to ensure that it runs as early as possible during the page load process.
add_action( 'template_redirect', 'disable_author_pages', 1 );

This snippet evaluates if the viewed page is an author page. If true, the visitor will be redirected to the homepage using the wp_redirect() function.

The function is added to the template_redirect action with a priority of 1 to run early during page load. This is useful for sites with a single author or those that want to maintain a consistent branding.

Step 3: Save and Apply Your Changes

After adding the code, save the changes to your functions.php file by clicking the Update File button at the bottom of the screen.

Step 4: Test Your Website’s Functionality

To ensure the author pages have been successfully disabled, visit your website, click on an author’s name, or input their username in the URL. If configured correctly, visitors will be redirected to the homepage.

Conclusion

As we conclude this comprehensive tutorial, you now have the knowledge to expertly disable author pages in WordPress and redirect your visitors to the homepage.

This customization allows your website to be more aligned with your user experience goals, without having to rely on external WordPress plugins.


Stay in the loop with our web development newsletter - no spam, just juicy updates! Join us now. Join our web development newsletter to stay updated on the latest industry news, trends, and tips. No spam, just juicy updates delivered straight to your inbox. Don't miss out - sign up now!


We’ve tried our best to explain everything thoroughly, even though there’s so much information out there. If you found our writing helpful, we’d really appreciate it if you could buy us a coffee as a token of support.

Also, if you’re interested in learning more about WordPress, Javascript, HTML, CSS, and programming in general, you can subscribe to our MailChimp for some extra insights.

Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.