Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Remove a query parameter from the URL (e.g. fbclid) and replace the history with the cleaner URL
// Using jQuery
// Remove fbclid
function removeParam(parameter) {
let params = new URLSearchParams(;
let urlParts = document.location.href.split('?');
let newUrl;
// Delete the passed parameter if present (no need to check)
if (params.toString() !== "") {
// If any other parameters were present, reappend
newUrl = urlParts[0] + '?' + params.toString()
} else {
newUrl = urlParts[0];
// Stripping a parameter should not push a new history state, hence replaceState
history.replaceState('', document.title, newUrl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.