Get current page URL in WordPress

Here is a handy snippet with which you can easily get current page URL on your WordPress website. It doesn’t matter if you need it on single post, page, home, category, tag, custom post type or any other WordPress template.

You can use this piece of code inside any template on your WordPress website.

/**
 * Insert your code here
 */
global $wp;//call wp global variable
$current_url = home_url(add_query_arg(array(),$wp->request));

 

«