You get the current path with remove_query_arg( '' )
. Combine it with site_url()
, and you have the full current request URI:
$url = untrailingslashit( site_url() );
$url .= remove_query_arg( '' );
Be aware that remove_query_arg()
doesn’t return a sanitized value, so you have to use esc_url()
if you want to print it to a page. Otherwise, someone could inject malicious code into your site in an URL parameter.
wp_get_referer()
is for form submissions, it looks for a request parameter _wp_http_referer
and is not relevant in your case.