admin管理员组文章数量:1315992
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.
本文标签: How to avoid redirect 302 in wordpress to the author pages
版权声明:本文标题:How to avoid redirect 302 in wordpress to the author pages? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741983197a2408521.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论