Replace existing canonical tag with javascript

Philip is freelancer

If you feel the content is useful. Thank for me with a coffee 😊

May 10, 2022 01:50 pm

If you have 2 websites with similar or similar content. You will be penalized by google for duplicate content. Need to mark 1 of the two pages as duplicate with the "canonical" meta tag

We can do it with JavaScript.

Add code css

<script>

var canonical_link = document.querySelector('link[rel="canonical"]');

canonical_link.href = 'https://yourlink.com/abc-name';

</script>

Insert this code in header.


If you feel the content is useful. Thank for me with a coffee 😊