tribe_append_path( string $url, string $path )
Append a path fragment to a URL preserving query arguments and fragments.
Contents
Parameters
- $path
-
(string) (Required) The path to append to the existing, if any, one., e.g.
/some/path
- $url
-
(string) (Required) A full URL in the
http://example.com/?query=var#frag
format.
Return
(mixed|string)
Source
File: src/functions/utils.php
function tribe_append_path( $url, $path ) { $path = trim( $path, '/' ); $query = @parse_url( $url, PHP_URL_QUERY ); $frag = @parse_url( $url, PHP_URL_FRAGMENT ); if ( ! ( empty( $query ) && empty( $frag ) ) ) { $url = str_replace( '?' . $query, '', $url ); $url = str_replace( '#' . $frag, '', $url ); $query = $query ? '?' . $query : ''; $frag = $frag ? '#' . $frag : ''; } $url = trailingslashit( esc_url_raw( trailingslashit( $url ) . $path ) ); $url .= $query . $frag; return $url; }
Changelog
Version | Description |
---|---|
4.3 | Introduced. |