Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_remove_qs_args_if_not_in_url() WordPress Function

The `remove_qs_args_if_not_in_url()` function is used to remove query string arguments from a URL if they are not present in the current URL. This can be useful for cleaning up dynamic URLs that may have been generated by a script.

_remove_qs_args_if_not_in_url( string $query_string, array $args_to_check, string $url ) #

Removes arguments from a query string if they are not present in a URL DO NOT use this in plugin code.


Parameters

$query_string

(string)(Required)

$args_to_check

(array)(Required)

$url

(string)(Required)


Top ↑

Return

(string) The altered query string


Top ↑

Source

File: wp-includes/canonical.php

function _remove_qs_args_if_not_in_url( $query_string, array $args_to_check, $url ) {
	$parsed_url = parse_url( $url );

	if ( ! empty( $parsed_url['query'] ) ) {
		parse_str( $parsed_url['query'], $parsed_query );

		foreach ( $args_to_check as $qv ) {
			if ( ! isset( $parsed_query[ $qv ] ) ) {
				$query_string = remove_query_arg( $qv, $query_string );
			}
		}
	} else {
		$query_string = remove_query_arg( $args_to_check, $query_string );
	}

	return $query_string;
}


Top ↑

Changelog

Changelog
VersionDescription
3.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.