In my theme when I try to access an author's page when I'm offline, it does a 302 redirect to the home page, I was looking at the theme files and in author.php I see the following code that I think does the redirection:
if ( ! is_user_logged_in() ) {
wp_safe_redirect( home_url() );
exit;
}
get_header();
I don't use a child theme, so I'd like to avoid that redirect with some snippet or best practice. I have searched, but what I see are answers to how to make a snippet for a redirect but not to avoid it.
In my theme when I try to access an author's page when I'm offline, it does a 302 redirect to the home page, I was looking at the theme files and in author.php I see the following code that I think does the redirection:
if ( ! is_user_logged_in() ) {
wp_safe_redirect( home_url() );
exit;
}
get_header();
I don't use a child theme, so I'd like to avoid that redirect with some snippet or best practice. I have searched, but what I see are answers to how to make a snippet for a redirect but not to avoid it.
Share Improve this question asked Nov 18, 2020 at 18:15 DrWhoDrWho 153 bronze badges 01 Answer
Reset to default 0but what I see are answers to how to make a snippet for a redirect but not to avoid it.
That's because you can't. If we could turn wp_safe_redirect
or wp_redirect
into a non-operation and disable it, the next statement is always exit;
which ends the request. The result here would be that your author archives have no HTML and the browser displays a blank screen. At most you might be able to change where it redirects to, but disabling the redirect via hooks and filters is not an available option.
For this reason, a snippet cannot work. Unless your theme provides a filter to toggle this behaviour, there is nothing to hook into. Based on the code you shared, this theme has not done that.
So to fix this, you have 3 options:
- Modify the theme to remove the redirect
- Use a child theme that replaces
author.php
with a version that removes the redirect - Petition the theme vendor to remove this or provide a setting to toggle it, and wait for the update
Options 2 and 3 would be best practice.