admin管理员组文章数量:1435859
I am trying to redirect any visitors to the dashboard unless they land on a specific custom post type (fruits).
So the following URLs would all redirect to the dashboard...
But the following would work as usual..
I have this so far...
function redirect_to_backend() {
if (!is_singular( 'fruits' )) {
wp_redirect( admin_url(), 301 );
exit();
}
}
add_action( 'init', 'redirect_to_backend' );
But this is not working, anyone point me in the right direction?
I am trying to redirect any visitors to the dashboard unless they land on a specific custom post type (fruits).
So the following URLs would all redirect to the dashboard...
https://www.example/contact
https://www.example/sales
https://www.example/blog
But the following would work as usual..
https://www.example/fruits/apple
https://www.example/fruits/grape
https://www.example/fruits/banana
I have this so far...
function redirect_to_backend() {
if (!is_singular( 'fruits' )) {
wp_redirect( admin_url(), 301 );
exit();
}
}
add_action( 'init', 'redirect_to_backend' );
But this is not working, anyone point me in the right direction?
Share Improve this question edited Mar 19, 2019 at 16:25 fightstarr20 asked Mar 19, 2019 at 16:20 fightstarr20fightstarr20 1,1358 gold badges26 silver badges47 bronze badges1 Answer
Reset to default 3The earliest hook that is_singular()
will work on is wp
. replace init
with wp
in your add_action
call
本文标签: Redirect all users to dashboard unless custom post type
版权声明:本文标题:Redirect all users to dashboard unless custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745674873a2669791.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论