Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/remove query arg

This page redirects to an external site: https://developer.wordpress.org/reference/functions/remove_query_arg/

Description

Removes an item or list from the query string.

Usage

// individual parameter
<?php remove_query_arg$key$query ?>

// multiple parameters in an array
<?php remove_query_arg( array('$key1''key2''key3'), $query ?>

Parameters

$key
(string|array) (required) Query key or keys to remove.
Default: None
$query
(boolean) (optional) When false uses the $_SERVER value.
Default: false

Return Values

(string) 
New URL query string. Note that this string may contain unescaped data not intended for a URL. The result should be passed through esc_url() before being output as HTML, in a link.

Examples

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. <?php
// This would output '/client/?type=value2&date=value3'
echo esc_urlremove_query_arg'details' ) );

// This would output '/client/'
$arr_params = array( 'details''type''date');
echo 
esc_urlremove_query_arg$arr_params ) );
?>
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, because the value is known to be safe: <?php
// This would output 'http://www.example.com/2014/03/11/'
echo remove_query_arg'details',  'http://www.example.com/2014/03/11/?details=value1');

// This would output 'http://www.example.com/2014/03/11/?type=value2&date=value3'
echo remove_query_arg'details',  'http://www.example.com/2014/03/11/?details=value1&type=value2&date=value3');

// This would output 'http://www.example.com/2014/03/11/'
$arr_params = array( 'details''type''date');
echo 
remove_query_arg$arr_params'http://www..example.com/2014/03/11/?details=value1&type=value2&date=value3');
?>

Notes

Change Log

Since: 1.5.0

Source File

remove_query_arg() is located in wp-includes/functions.php.

Related

add_query_arg()

See also index of Function Reference and index of Template Tags.