request))", etc."/> request))", etc.">
Home > Article > CMS Tutorial > How to get the current page URL in WordPress
How does WordPress get the current page URL address
We often need to get the current page URL when making WordPress templates Address, here I will introduce to you how to get the URL address of the current page.
(Recommended tutorial: WordPress Tutorial)
1. Use WordPress To achieve it with native functions, the code is as follows:
$current_url = home_url(add_query_arg(array()));
2. A universally applicable method, the code is as follows:
$current_url = home_url(add_query_arg(array(),$wp->request));
3. Directly in WordPress Add the following code:
< ? php // 说明:获取完整URL function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") { $pageURL. = "s"; } $pageURL. = "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL. = $_SERVER["SERVER_NAME"]. ":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL. = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } ?>
and then call it as follows, the code is as follows:
<?php echo curPageURL(); ?>
The above is the detailed content of How to get the current page URL in WordPress. For more information, please follow other related articles on the PHP Chinese website!