如何获取页面的当前路径?
我知道如何在我的模板上执行此操作,但我需要在 functions.php 上执行此操作。它必须在 send_headers 钩子之前,因为我将使用此信息来设置 cookie。
我尝试过使用 PHP,但它显示了 functions.php 的路径...
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
尝试这个。
echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];