Hreflang Implementation in sitemap.xml for HubSpot Multilingual Site
SOLVE
Hello, we are localizing our website and need to implement hreflang via sitemap. However, we are not able to edit the sitemap.xml file directly. Is there a way to:
Add alternate hreflang links via sitemap in HubSpot?
Add a custom sitemap file that includes xhtml:link?
Automatically handle hreflang for multilingual content hosted in subdirectories like /de/?
since the sitemap.xml is being generated automatically it's unfortunately not possible to modify it.
Something you might want to look at is your themes base.html (might have a different name) and add your language to it.
Technically it should be possible to create your own sitemap.xml, put it into the file-manager or design-manager and reference it in the base.html with some HubL like
{# File-Manager example #}
{% if content.translated_content.language == "English"%}
{% set sitemap_url = "path-to-english-sitemap.xml" %}
{% elif content.translated_content.language == "Deutsch" %}
{% set sitemap_url = "path-to-german-sitemap.xml" %}
{% endif %}
{# Design-Manager example #}
{% if content.translated_content.language == "English"%}
{% set sitemap_url = get_asset_url("path-to-english-sitemap.xml") %}
{% elif content.translated_content.language == "Deutsch" %}
{% set sitemap_url = get_asset_url("path-to-german-sitemap.xml") %}
{% endif %}
<link rel="sitemap" type="application/xml" title="Sitemap" href="{{ sitemap_url }}">
Please note that this won't replace your DOMAIN.com/sitemap.xml
since the sitemap.xml is being generated automatically it's unfortunately not possible to modify it.
Something you might want to look at is your themes base.html (might have a different name) and add your language to it.
Technically it should be possible to create your own sitemap.xml, put it into the file-manager or design-manager and reference it in the base.html with some HubL like
{# File-Manager example #}
{% if content.translated_content.language == "English"%}
{% set sitemap_url = "path-to-english-sitemap.xml" %}
{% elif content.translated_content.language == "Deutsch" %}
{% set sitemap_url = "path-to-german-sitemap.xml" %}
{% endif %}
{# Design-Manager example #}
{% if content.translated_content.language == "English"%}
{% set sitemap_url = get_asset_url("path-to-english-sitemap.xml") %}
{% elif content.translated_content.language == "Deutsch" %}
{% set sitemap_url = get_asset_url("path-to-german-sitemap.xml") %}
{% endif %}
<link rel="sitemap" type="application/xml" title="Sitemap" href="{{ sitemap_url }}">
Please note that this won't replace your DOMAIN.com/sitemap.xml
HubSpot automatically manages hreflang tags for multilingual content, but only in the HTML head of the pages, not in the sitemap.xml, and you can’t upload or customize your own sitemap.
Q1. Can I add hreflang tags via sitemap in HubSpot? Ans - No, HubSpot doesn’t support custom hreflang entries in its sitemap. Instead, it handles hreflang through <link rel="alternate" hreflang="..."> tags in the HTML <head> of each language version.
Q2. Can I upload my own sitemap with XHTML: link tags? Ans - No, HubSpot’s sitemap is auto-generated, and you can’t override or upload a custom version.
Q3. Does HubSpot add hreflang tags for subdirectories like /de/? Ans - Yes, as long as you use HubSpot’s built-in multi-language tools, it will auto-insert the correct hreflang tags in the page <head> for all language variants (e.g., /de/, /fr/, etc.).