Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Last active December 17, 2015 03:19
Show Gist options
  • Save wpscholar/5542587 to your computer and use it in GitHub Desktop.
Save wpscholar/5542587 to your computer and use it in GitHub Desktop.
A function for use within WordPress themes or plugins that fetches the current URL without the query string.
<?php
/**
* Helper function fetches current URL less the query string
*
* @return string
*/
function get_url(){
global $wp;
$url = parse_url( add_query_arg( $wp->query_string, '', home_url( $wp->request ) ) );
return $url['scheme'] . '://' . $url['host'] . ( isset($url['path'] ) ? $url['path'] : '' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment