

Get the URL of the Current Displayed Page
source link: https://pineco.de/snippets/get-the-url-of-the-current-displayed-page/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Get the URL of the Current Displayed Page
In WordPress, depending on what URL you want to query, there are many methods. For example, we usually access the URL with the get_permalink() function, but this solution only works for single views of any post type.
Let’s see how we can get the current URL in WordPress:
global $wp;
echo esc_url(home_url($wp->request));
Using $wp global, we can access our request, which we can pass to the home_url() function to convert to a full URL. The $wp->request includes just the path URL like /about/us.
If you want to get an URL with query parameters you should also use the add_query_arg() function like so:
global $wp;
echo esc_url(home_url(add_query_arg([$_GET]), $wp->request));
As you see, we also used the esc_url() function to escape our URLs before displaying them.
Recommend
-
4
The result of the WCF service causes the browser to be displayed so that "the page can not be displayed" in some cases advertisements I am wor...
-
8
Get Page URL from Slug in WordPress We use cookies for commenting and analytics. For more details, please visit our privacy page.
-
8
How to get current url Jquery vanilla Javascript Satinder Singh / January 09, 2021 /
-
7
Get the Blog Page URL in WordPress We use cookies for commenting and analytics. For more details, please visit our privacy page.
-
6
How can I get the screen reader to read out an error message that I displayed inline on a page? Raymond October 18th, 2021 ...
-
7
Get Current Tab URL From Chrome Extension in Go February 02, 2018 Build
-
4
How to get current page URL in PHP 1484 views 2 years ago PHP Use the PHP $_SERVER Superglobal Va...
-
5
How to Get the Current URL with JavaScript 1189 views 2 years ago Javascript Use the window.locat...
-
10
Laravel 8 Get Current URL With Parameters 4473 views 9 months ago Laravel Sometimes you might want to find the curr...
-
10
How to Get Current URL in Laravel 2415 views 10 months ago Laravel In blade files or Controllers, you may want to c...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK