Переадресация в вордпресс
Решено
Расскажите о переадресации вордпресс. Будет даже лучше если привести примеры как реализовать переадресацию после например регистрации или добавления комментария.
Как и какие фильтры использовать что бы настроить редирект после определенных действий.
1 Ответ(ы)
Ответ
Перенаправление пользователей после успешной регистрации
add_filter( 'registration_redirect', 'redir_new_users' ); function redir_new_users() { // change the slug below with your own page's slug return home_url( '/white-paper/' ); }
Перенаправление пользователей после входа и выхода из системы
// вход add_filter( 'login_redirect', 'send_subscribers_home', 10, 3 ); function send_subscribers_home( $location, $request, $user ) { global $user; if ( isset( $user->roles ) && is_array( $user->roles ) ) { if ( in_array( 'subscriber', $user->roles ) ) { return home_url(); } else { return $redirect_to; } } return; }
// выход add_filter( 'logout_redirect', 'goodbye_subscribers', 10, 3 ); function goodbye_subscribers( $location, $request, $user ) { global $user; if ( isset( $user->roles ) && is_array( $user->roles ) ) { if ( in_array( 'subscriber', $user->roles ) ) { // change the slug below with your own page's slug return home_url( '/goodbye/' ); } else { return $redirect_to; } } return; }
Перенаправление пользователей после сброса пароля
add_filter( 'lostpassword_redirect', 'lostpassword_message' ); function lostpassword_message( $location ) { // change the slug below with your own page's slug return '/lost-password-notice/'; }
Перенаправление пользователей после оставления комментариев
add_filter( 'comment_post_redirect', 'redirect_to_newsletter' ); function redirect_to_newsletter( $location ) { // change the slug below with your own page's slug return '/subscribe-to-our-newsletter/'; }
Перенаправление со страницы с id 77
add_action( 'template_redirect', function() { if( is_page(77) ){ wp_redirect( 'http://example.org/path/to/subscribe', 301 ); exit; } } );
Полезные функции:
https://developer.wordpress.org/reference/functions/wp_redirect/
https://codex.wordpress.org/Function_Reference/wp_safe_redirect