wordpress page redirects to homepage code example
Example 1: wp_redirect to home page
function redirect_to_home() {
if(!is_admin() && is_page('2')) {
wp_redirect(home_url());
exit();
}
}
add_action('template_redirect', 'redirect_to_home');
Example 2: redirect wordpress
add_action( 'template_redirect', 'redirect_to_other_page' );
function redirect_to_other_page() {
if ( is_page( 143 ) ) {
wp_redirect( '"'.home_url().'/services/messenger/"', 301 );
///wp_redirect( 'example.com/page', 301 );
exit;
}
}