Created
January 9, 2024 19:52
-
-
Save nocodesupplyco/6db4778c6bfc3d12094652985d8c380b to your computer and use it in GitHub Desktop.
Set canonical to match pagination if using Webflow pagination
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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