remove_query_arg() WordPress Function

The remove_query_arg() function is a handy way to remove query arguments from a URL in WordPress. It takes two parameters: the URL string and the query argument to remove. For example, if you wanted to remove the "view" query argument from a URL, you would use remove_query_arg() like so: remove_query_arg( 'view', 'http://example.com/page?view=list' ); This would return the URL http://example.com/page.

remove_query_arg( string|string[] $key, false|string $query = false ) #

Removes an item or items from a query string.


Parameters

$key

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

$query

(false|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

Changelog
VersionDescription
1.5.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.

Show More
Show More