The WPFolks app is out on iPhone and Android. Free, no ads. Download on the App Store Get it on Google Play
Skip to main content
Login Join
Snippet · PHP

Get Current WordPress Page URL Safely

Shared by Hiral solanki · September 9, 2026

23 views
1 upvote
Back to Snippets

Output: echo esc_url( mytheme_get_current_url() );

/**
 * Get the current frontend URL.
 *
 * @return string
 */
function mytheme_get_current_url() {

	global $wp;

	return home_url(
		add_query_arg(
			array(),
			$wp->request
		)
	);
}
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments

Proudly supported by