Skip to content

Commit

Permalink
Add additional functions for getting parts of the URL
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronHolbrook authored Jan 14, 2019
1 parent 73329ff commit 3e44032
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,39 @@ function get_current_url() {
return home_url( add_query_arg( null, null ) );
}

/**
* Get an array of parts of the current URL
*
* @return mixed
*/
function get_current_url_parts() {
$current_url = get_current_url();

$url_parts = parse_url( $current_url );

return $url_parts;
}

/**
* Returns the current URL, but without query args.
*
* @return string
*/
function get_current_url_clean() {
$current_url = get_current_url();
$url_parts = get_current_url_parts();

$url_parts = parse_url( $current_url );
return home_url( $url_parts['path'] ?? null );
}

return home_url( $url_parts['path'] );
/**
* Returns the current path
*
* @return string
*/
function get_current_url_path() {
$url_parts = get_current_url_parts();

return $url_parts['path'] ?? '/';
}

/**
Expand Down

0 comments on commit 3e44032

Please sign in to comment.