Skip to content

Instantly share code, notes, and snippets.

@nocodesupplyco
Created January 9, 2024 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nocodesupplyco/6db4778c6bfc3d12094652985d8c380b to your computer and use it in GitHub Desktop.
Save nocodesupplyco/6db4778c6bfc3d12094652985d8c380b to your computer and use it in GitHub Desktop.
Set canonical to match pagination if using Webflow pagination
// Original code source and use agreement here: https://gist.github.com/rileyrichter/b2e5b5d9fe8952372ce49fafc75dea8b
const canonical = document.querySelector('link[rel="canonical"]');
const urlParams = new URLSearchParams(window.location.search);
const paginationParam = Array.from(urlParams.entries()).find(([key]) =>
/^[a-z0-9]{8}_page$/.test(key)
);
if (paginationParam) {
const canonical = document.querySelector('link[rel="canonical"]');
canonical.href = `${canonical.href}?${paginationParam.join("=")}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment