0

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.

0

1 Answer 1

0

but 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:

  1. Modify the theme to remove the redirect
  2. Use a child theme that replaces author.php with a version that removes the redirect
  3. 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.

5
  • Thank you @tom-j-nowell, I will have to make the request ...
    – DrWho
    Nov 18, 2020 at 18:51
  • One doubt, as the redirect is for guest users. Is there a way for visitors to see the site as a registered user without registering?
    – DrWho
    Nov 21, 2020 at 20:34
  • It depends.... , it's probably more complicated than just not redirecting them and depends massively on what that template actually does, it is not something I can tell you based on what's been shared in this question. It could be as simple as not redirecting. It might be complex and require extensive changes. It may even be impossible because of what that template does. I don't know, and I can't know with just what you've shared.
    – Tom J Nowell
    Nov 21, 2020 at 22:50
  • Eitherway that is a new question, new questions should be asked as new questions on the site, but you'll need a lot more info than this. To be honest it would probably be closed as off topic anyway, and you'd be directed to the theme vendors support route. If you bought a theme and want to ask questions about working with it, you really should be talking to the people who sold you it rather than random people online. What you're wanting isn't a generic WP question that has an one fits all answer, but rather a specific question about an unknown themes code
    – Tom J Nowell
    Nov 21, 2020 at 22:52
  • Yes, I asked a new question right now, thanks and you are very right, the problem is that they do not respond after a week of waiting and of course I am trying to solve it in some way, I have tried a child theme but the theme for child theme is not well prepared , So I do not know what to do...
    – DrWho
    Nov 21, 2020 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.