How to get current page URL in WordPress

Md Riyazuddin Verified

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

Comments

Leave a Comment