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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745674874a4639626.html
评论列表(0条)