Skip to main content
Login Join
Snippet · PHP

Get Current WordPress Page URL Safely

Shared by Hiral solanki · September 9, 2026

2 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