Skip to main content

Redirect for authors without WP_post articles

I just made a snippet for those who uses Blog posts (as I do). If you use any kind of Fluent frame overiding on any theme, when someone goes on /author/username/ URL where are no WP blog posts, it shows up non-overriden page like "not found" or "no articles found". In that case this conditioned redirect snippet uses hook for this kind of situation and in case of no author posts it redirects to user profile in Fluent Community. Feel free to use it. If you are interested in more solutions, give me follow there to not miss it.

Snippet below:

/**

  • Redirect "not found" author pages (no blog posts)
  • to the Fluent Community profile URL.
  • Example:
  • /author/username/ β†’ /portal/u/username/
    */
    add_action('template_redirect', function() {
// Check if we're on an author archive page
if (is_author()) {
    global $wp_query;
    $author_name = get_query_var('author_name'); // Get the author slug (username)

    // Check if there are NO posts for this author
    if ($wp_query->found_posts === 0 && !empty($author_name)) {

        // Build the new Fluent Community profile URL
        $new_url = home_url('/portal/u/' . $author_name . '/');

        // Perform a 301 (permanent) redirect
        wp_redirect($new_url, 301);
        exit;
    }
}

});

Drive Zone

Boken not found page

Drive Zone

With active snippet

Drive Zone

Author who has WP posts stay non-redirected