Is there a way to remove all query arg parameter in the URL added via add_query_arg(); without knowing the query key available for removal?

I'm looking for this kind of function remove_query_arg_all(); currently I'm removing the query_arg via preg_match REQUEST_URI, but not sure if it will cause any problem in the future.

  • Did you try searching stackoverflow ? – Sumit Apr 20 '16 at 17:09

You can explode URL by ? and take the first part:

$url = explode( '?', esc_url_raw( add_query_arg( array() ) ) );

$no_query_args = $url[0];

You can do this in one line if your aim is to remove all of the params from the current $_GET


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.