On this page
strip_fragment_from_url( string $url ): string
Strips the #fragment from a URL, if one is present.
Parameters
$urlstring Required-
The URL to strip.
Return
string The altered URL.
Source
File: wp-includes/canonical.php. View all references
function strip_fragment_from_url( $url ) {
$parsed_url = wp_parse_url( $url );
if ( ! empty( $parsed_url['host'] ) ) {
$url = '';
if ( ! empty( $parsed_url['scheme'] ) ) {
$url = $parsed_url['scheme'] . ':';
}
$url .= '//' . $parsed_url['host'];
if ( ! empty( $parsed_url['port'] ) ) {
$url .= ':' . $parsed_url['port'];
}
if ( ! empty( $parsed_url['path'] ) ) {
$url .= $parsed_url['path'];
}
if ( ! empty( $parsed_url['query'] ) ) {
$url .= '?' . $parsed_url['query'];
}
}
return $url;
}
Related
Uses
| Uses | Description |
|---|---|
| wp_parse_url() wp-includes/http.php | A wrapper for PHP’s parse_url() function that handles consistency in the return values across PHP versions. |
Used By
| Used By | Description |
|---|---|
| do_enclose() wp-includes/functions.php | Checks content for video and audio links to add as enclosures. |
| redirect_canonical() wp-includes/canonical.php | Redirects incoming links to the proper URL based on the site url. |
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/strip_fragment_from_url