strip_fragment_from_url

The timeline below displays how wordpress function strip_fragment_from_url has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Strips the #fragment from a URL, if one is present.
 *
 * @since 4.4.0
 *
 * @param string $url The URL to strip.
 * @return string The altered URL.
 */
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;
}

WordPress Version: 5.5

/**
 * Strips the #fragment from a URL, if one is present.
 *
 * @since 4.4.0
 *
 * @param string $url The URL to strip.
 * @return string The altered URL.
 */
function strip_fragment_from_url($url)
{
    $parsed_url = parse_url($url);
    if (!empty($parsed_url['host'])) {
        // This mirrors code in redirect_canonical(). It does not handle every case.
        $url = $parsed_url['scheme'] . '://' . $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;
}

WordPress Version: 4.9

/**
 * Strips the #fragment from a URL, if one is present.
 *
 * @since 4.4.0
 *
 * @param string $url The URL to strip.
 * @return string The altered URL.
 */
function strip_fragment_from_url($url)
{
    $parsed_url = @parse_url($url);
    if (!empty($parsed_url['host'])) {
        // This mirrors code in redirect_canonical(). It does not handle every case.
        $url = $parsed_url['scheme'] . '://' . $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;
}

WordPress Version: 4.4

/**
 * Strips the #fragment from a URL, if one is present.
 *
 * @since 4.4.0
 *
 * @param string $url The URL to strip.
 * @return string The altered URL.
 */
function strip_fragment_from_url($url)
{
    $parsed_url = @parse_url($url);
    if (!empty($parsed_url['host'])) {
        // This mirrors code in redirect_canonical(). It does not handle every case.
        $url = $parsed_url['scheme'] . '://' . $parsed_url['host'];
        if (!empty($parsed_url['port'])) {
            $url .= ':' . $parsed_url['port'];
        }
        $url .= $parsed_url['path'];
        if (!empty($parsed_url['query'])) {
            $url .= '?' . $parsed_url['query'];
        }
    }
    return $url;
}