Get current page URL in WordPress – The WordPress solution

Get current page URL in WordPress – The WordPress solution

You might need link to current page or post due to number of requirements provided by your clients. With a simple code we can get current page URL using WordPress native functions.

Such case usually occurs when you are developing a plugin or you need a functionality on a specific page for example on “about us” page if you need different functionality form other pages, you can get the URL using following snippet:

 

global $wp;
$current_url = home_url(add_query_arg(array(),$wp->request));

 

You can write the above code in functions.php file or your plugin or template file.

You can also fetch URL in core PHP but in this post we have mentioned native WordPress solution.

Related Posts