PHPWordPress

Get current page URL in WordPress – The WordPress solution

0
2.8k
2018 / 05 / 08

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.

Hi, I am a full-stack web developer with 5+ years of experience in working with different web technologies. Do you want to ask something? just send me a message through the contact form. Please visit my portfolio at hamzamehmood.com. Thanks