I've created a function which suppose to redirect a user if /resources/ string is found in url of page he's trying to visit,
but it's not working, can someone tell me what went wrong?
function redirect_collateral() {
if (strpos($_SERVER['REQUEST_URI'], "/resources/") !== false){
$url = $_SERVER['REQUEST_URI'];
$my_var = '';
$url = str_replace("/resources/", $my_var, $url );
header("Location: $url");
}
}
add_action( 'init', 'redirect_collateral' );