Add to collection
Md Riyazuddin

Md Riyazuddin

Verified

How to get current page URL in WordPress

In this, you will get the current page URL in WordPress with a query or plain permalink.


// it will echo plain permalink without query stirngs
global $wp;
echo home_url( $wp->request );

//$wp->request includes the path part of the URL, eg. /path/to/page and home_url() outputs the URL in Settings > General, but you can append a path to it, so we're appending the request path to the home URL in this code.

//it will echo plain permalink with query stirngs
global $wp;
echo add_query_arg( $wp->query_vars, home_url( $wp->request ) );

References and Credits

Tagged with: WordPress

Comments 0

  • Sorry!! No comment posted yet. Become the first user to give comment.
Add a comment

Would you like to write for w3 sniff?

Become part of an amazing group of contributors and authors and start writing for us

Join Now
// it will echo plain permalink without query stirngs
global $wp;
echo home_url( $wp->request );

//$wp->request includes the path part of the URL, eg. /path/to/page and home_url() outputs the URL in Settings > General, but you can append a path to it, so we're appending the request path to the home URL in this code.

//it will echo plain permalink with query stirngs
global $wp;
echo add_query_arg( $wp->query_vars, home_url( $wp->request ) );
Feedback submitted successfully.