When a non-logged-in reader visits a private WordPress post or page, she gets a 404 “not found” error message, as if the post didn’t exist at all. That’s great if you don’t want the world to know that the post exists, but what if you’re doing something less clandestine, like members-only content? You do want people to know the post is there–they haven’t followed a bad link!–but they need to log in to see it. Then “not found” is misleading.
There are two ways you could make the user experience better: redirecting private 404s to the login screen with a message, or changing the 404 error text.
Redirecting private 404s to the login screen
If you’re going with the redirect option, you’ll need two small functions in your custom plugin or your theme’s functions.php file. The first checks whether the queried object (in this case, the post/page) is private, and if so, redirects to the login URL with a custom query argument and instructions to return the user to the original page after they’ve logged in.
The second function runs on the login screen. If the custom query argument is set, it adds a message telling the user they need to log in before viewing the original page.
Changing the 404 error text (in Genesis)
If you want to be a little less presumptuous about whisking users off to a login screen, you can instead filter the error message and give them the option of following the login link.
In most WordPress themes, you can edit your template files directly to add a wp_login_url() link. In Genesis, you need to filter the noposts text instead: