remove_query_arg( string|string[] $key, false|string $query = false ): string
Removes an item or items from a query string.
Description
Important: The return value of remove_query_arg() is not escaped by default. Output should be late-escaped with esc_url() or similar to help prevent vulnerability to cross-site scripting (XSS) attacks.
Parameters
-
$key
string|string[] Required -
Query key or keys to remove.
-
$query
false|string Optional -
When false uses the current URL.
Default:
false
Return
string New URL query string.
Source
File: wp-includes/functions.php
.
View all references
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 );
}
Changelog
Version | Description |
---|---|
1.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
Assuming we’re at the WordPress URL “http://www.example.com/client/?details=value1&type=value2&date=value3″…
Note the use of
esc_url()
before outputting the link.When you want to manipulate a URL that is not of the page your script is in, add the targeted URL in the second parameter as below. The use of
esc_url()
is not required here (though encouraged), because the value is known to be safe: