Guide: How to change the Rel=Canonical Link on Hubspot pages and posts

HubSpot offers no official way of changing this important SEO parameter. However, if you do need to change it there is a way! It’s very simple and just involves a snippet of jQuery code. Just edit the code snippet below with the address of your original content and then place it within your post or page to update it:

<script type="text/javascript">
window.onload = function myfunction () {
$('link[rel="canonical"]').attr('href', 'NEW-VALUE-HERE');
}
</script>

Change ‘NEW-VALUE-HERE’ to be the URL that you want to be the new href value of your HubSpot blog post’s canonical link tag.

Method

On a HubSpot COS page, you can add the code via the code view of the main rich text area for the page or post in question. Click the ‘<>’ button from the edit options of the rich text area to enter the code view and simply paste it in. Make sure you add your desired href value for your link tag. Update the page and check in your browser’s developer tools to make sure the code executes successfully.

Does it work?

The jQuery code will run on page load and update your pages source in the DOM. Because Google’s crawler can and will process JavaScript it will read and honour the changed href value of the canonical link tag on your HubSpot blog post. You can read more about this here.

 

Questions or comments? Let me know!