-
Hello,
I have several users on my website and have created a hero Element to display each user’s name, avatar, and description, on each author archive.
Now I have some users with no blog posts, but who nonetheless have an avatar, name, and description. However, when I go to their author archive page, nothing gets displayed — not even their names/avatar/descriptions. The structural elements of the hero Element are present (e.g. containers, etc.), but it’s all empty so I basically get a white page.
Is that normal behavior? I would like the user information to display even if they have not authored any blog post.
-
Fernando
Hi John,
That’s normal behavior. Archive pages with no posts default to the no-results.php template.
It’s a bit complicated to alter this behavior. You’ll need to use the Child theme, create a template for author archives specifically, and alter this part of the code: https://github.com/tomusborne/generatepress/blob/adfe090929b0515cdf894f4c6b722cfe8c0790dc/archive.php#:~:text=generate_do_template_part(%20%27none%27%20)%3B
Then, create a template for your archive page that don’t have posts.
Alternatively, I would suggest adding a post for all users.
-
I understand; thank you Fernando.
I want to avoid modifying the theme, even from a Child Theme, to avoid having to maintain it ongoing with future updates.
Instead, I’ve chosen to redirect the empty author archives to a static page where I can give some explanation to the user. I used this code snippet:
add_action( 'template_redirect', 'redirect_empty_author_archive' ); function redirect_empty_author_archive() { if ( is_author() && !have_posts() ) { wp_redirect( home_url( '/no-user-info' ), 301 ); exit; } }
Sharing here for anyone who might be interested in a similar solution.
Thank you
-
Fernando
I see. You’re welcome, John! Thank you for sharing your solution!
- You must be logged in to reply to this topic.