0

trying to watch for a specific url on the site, and based on that add a string to the url then redirect. I'm searching the substring '/product/' so it needs to be dynamic~ish (wordpress multisite, needs to work on all sites.

Tried this in functions.php.. not sure how/when to call it.

 function fancy_redirect() {
    $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 
    if ( (strpos($actual_link, '/product/') !== false) &&   (strpos($actual_link, '?start_customizing=yes') === false)) {
        header('Location: '. $actual_link . '?start_customizing=yes');
    }
}

Also tried it in javascript, this runs in console but not when live.

window.onload = function() {

  if(location.href.search("/product/") !== -1 && location.href.search("/?start_customizing=yes") === -1) {
    window.location = (location.href + "?start_customizing=yes");
  }

}
user2745054
  • 11
  • 1
  • 3

1 Answers1

0

Going to have to agree with @wawa on this one. If you built this functionality into the template of /product/, you could then redirect users to the appropriate URL

header("Location: http://example.com/product/". $new_location);
die();

Found this SO answer

Community
  • 1
  • 1