Get the current url.

(It’s easy to reach for get_the_permalink(); but this won’t work if you’re on an archive page.)

global $wp;

$current_url = home_url( add_query_arg( array(), $wp->request ) );