Last active
July 16, 2020 12:51
-
-
Save davidvandenbor/67a04ea2a64eea9d0f0907b0eb32b61f to your computer and use it in GitHub Desktop.
Add canonical url via JS in html
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
<script type='text/javascript'> | |
var link = !!document.querySelector("link[rel='canonical']") ? document.querySelector("link[rel='canonical']") : document.createElement('link'); | |
link.setAttribute('rel', 'canonical'); | |
link.setAttribute('href', location.protocol + '//' + location.host + location.pathname); | |
document.head.appendChild(link); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment