remove_query_arg( string|array $key, bool|string $query = false )
Removes an item or items from a query string.
Contents
Description Description
Parameters Parameters
- $key
-
(string|array) (Required) Query key or keys to remove.
- $query
-
(bool|string) (Optional) When false uses the current URL.
Default value: false
Return Return
(string) New URL query string.
Source 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 ); }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
1.5.0 | Introduced. |
More Information More Information
Usage: 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 ) );
User Contributed Notes 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: