0

如何获取页面的当前路径?

我知道如何在我的模板上执行此操作,但我需要在 functions.php 上执行此操作。它必须在 send_headers 钩子之前,因为我将使用此信息来设置 cookie。

我尝试过使用 PHP,但它显示了 functions.php 的路径...

4

2 回答 2

0

You should be able to get the request path with something like this in your functions.php file:

function current_request_path(){
  return $_SERVER['REQUEST_URI'];
}

If that doesn't work, you could always set the cookie with JavaScript after the page loads. You can get the current URL with via JavaScript using window.location.href

于 2013-04-16T14:36:57.880 回答
0

尝试这个。

echo "http://" . $_SERVER['HTTP_HOST']  . $_SERVER['REQUEST_URI'];
于 2013-04-16T14:32:48.550 回答