Redirect based on referer using Advanced Custom Fields
Try the template_redirect hook function portal_protection() { if ( get_field(‘enable_portal_protection’) && !current_user_can(‘administrator’) ) { $referring_url = get_field(‘referring_url’); $redirect_url = get_field(‘redirect_url’); $referer = $_SERVER[‘HTTP_REFERER’]; if ( $referer != $referring_url) { wp_redirect( $redirect_url ); exit; } } } add_action( ‘template_redirect’, ‘portal_protection’ ); Also use wp_redirect. it’s the WordPress way of redirecting.