remove_query_arg( string|array $key, bool|string $query = false )

Removes an item or items from a query string.


Description


Parameters

$key

(string|array) (Required) Query key or keys to remove.

$query

(bool|string) (Optional) When false uses the current URL.

Default value: false


Top ↑

Return

(string) New URL query string.


Top ↑

Source

File: wp-includes/functions.php

function remove_query_arg( $key, $query = false ) {
	if ( is_array( $key ) ) { // removing multiple keys
		foreach ( $key as $k ) {
			$query = add_query_arg( $k, false, $query );
		}
		return $query;
	}
	return add_query_arg( $key, false, $query );
}

Top ↑

Changelog

Version Description
1.5.0 Introduced.

Top ↑

More Information

Usage:

// individual parameter
esc_url( remove_query_arg( $key, $query ) );

// multiple parameters in an array
esc_url( remove_query_arg( array('$key1', 'key2', 'key3'), $query ) );