最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to avoid redirect 302 in wordpress to the author pages?

programmeradmin3浏览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.

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 0
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论