You can do this at an earlier moment by hooking into the right action, like template_redirect
, which fires right before the template will be displayed.
add_action( 'template_redirect', 'wpse14047_template_redirect' );
function wpse14047_template_redirect()
{
if ( is_author() ) {
$id = get_query_var( 'author' );
// get_usernumposts() is deprecated since 3.0
$post_count = count_user_posts( $id );
if ( $post_count <= 0 ) {
//This line could also be wp_redirect
include( STYLESHEETPATH .'/author-redirect.php' );
exit;
}
}
}