> ## Content Index
> Fetch the complete content index at: https://sanghunkang.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Multilingual Ghost CMS Blog: 5. Making Home Links Language Aware
- URL: https://sanghunkang.com/multilingual-ghost-cms-5-handling-multilingual-home-link-en/
- Published: 2026-09-26T14:37:51.000Z
- Updated: 2026-09-26T14:41:22.000Z
- Author: Sanghun Kang
- Tags: Ghost, #en, #multi

This explains how to make the home links in the navigation bar, footer, and error page point to the correct language-specific homepage.

![](https://sanghunkang.com/content/images/2025/02/image.png)

Home link in the navigation bar

![](https://sanghunkang.com/content/images/2025/02/image-1.png)

Home link in the footer

![](https://sanghunkang.com/content/images/2025/02/image-2.png)

Home link on the error page

There are home links in the navigation bar, footer, and error page. These links are set to @site.url, and regardless of the multilingual settings, they only point to the main page of the default language. Let's modify them so they point to the currently active language instead.

![](https://sanghunkang.com/content/images/2025/02/Screenshot-2025-02-16-at-08.26.45.png)

default.hbs

```
<a class="gh-head-logo{{#unless @site.logo}} no-image{{/unless}}" href="{{#if (block "lang")}}{{@site.url}}/{{block "lang"}}{{else}}{{@site.url}}{{/if}}">
```

In default.hbs, it works properly if you handle it by using the block "lang" in an if condition, the same way as before.  
However, this approach does not work properly on the error page or tag page. That is because these pages do not include index-ko or index-en, and they also do not explicitly assign "lang" values like post or page do. So I decided not to rely on lang.

The new idea is to change the approach so that, as in tag.hbs, it retrieves the selectedLanguage value stored in localStorage and updates the URL based on that value.

Since this needs to be done in default, tag, and error as well, I wanted to create a separate file and reuse it. I made separate functions for these two tasks and stored them in a separate util.js file so they could be reused across multiple files.

```javascript
function getSelectedLanguage() {
  return localStorage.getItem("selectedLanguage") || "en";
}

function updateLink(selector, language) {
  const element = document.querySelector(selector);
  if (element) {
    let siteUrl = element.getAttribute("href");
    if (!siteUrl.endsWith("/")) {
      siteUrl += "/";
    }
    element.setAttribute("href", `${siteUrl}${language}/`);
  }
}

```

assets/js/util.js

Using these functions, let's update all files that contain @site.url links.

You can load the newly created js file using the {{asset}} helper.

`<script type="text/javascript" src="{{asset 'js/util.js'}}"></script>`  
Reference:

[Ghost Handlebars Theme Helpers: assetTake the pain out of asset management when developing a Ghost theme and managing your publication. Read more about asset management with Ghost themes! 👻![](https://sanghunkang.com/content/images/icon/favicon.ico)Ghost - The Professional Publishing Platform![](https://sanghunkang.com/content/images/thumbnail/ghost-docs.png)](https://ghost.org/docs/themes/helpers/asset/?ref=sanghunkang.com)

# Full code

You can check the full code here on GitHub.

[0.0.5 · sanghunka/ghost-multilingual-theme@59b6cc1Contribute to sanghunka/ghost-multilingual-theme development by creating an account on GitHub.![](https://sanghunkang.com/content/images/icon/pinned-octocat-093da3e6fa40.svg)GitHubsanghunka![](https://sanghunkang.com/content/images/thumbnail/59b6cc146fbb63f1a6ae0f3a50be37c00780acf4)](https://github.com/sanghunka/ghost-multilingual-theme/commit/59b6cc146fbb63f1a6ae0f3a50be37c00780acf4?ref=sanghunkang.com)

# error-404.hbs

Let's add this code at the very bottom.

It's simple. It gets selectedLanguage and changes the href of .error-link to match it.

```
<script type="text/javascript" src="{{asset 'js/util.js'}}"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
    const selectedLanguage = getSelectedLanguage();
    if (selectedLanguage !== 'en') {
        updateLink('.error-link', selectedLanguage);
    }
});
</script>
```

Try entering any URL (e.g. {host}/ko/404error) and check whether the home link correctly points to {host}/ko/.

![](https://sanghunkang.com/content/images/2025/02/image-3.png)

ko

![](https://sanghunkang.com/content/images/2025/02/image-4.png)

en

# error.hbs

```javascript
<script type="text/javascript" src="{{asset 'js/util.js'}}"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
    const selectedLanguage = getSelectedLanguage();
    if (selectedLanguage !== 'en') {
        updateLink('.error-link', selectedLanguage);
        updateLink('.site-nav-logo', selectedLanguage);
    }
});
</script>
```

# tag.hbs

I replaced this code, which I had implemented before,

`const selectedLanguage = localStorage.getItem('selectedLanguage') || 'en';`

with the newly created function.

```
<script type="text/javascript" src="{{asset 'js/util.js'}}"></script>

const selectedLanguage = getSelectedLanguage();
```

# default.hbs

```javascript
<script type="text/javascript" src="{{asset 'js/util.js'}}"></script>
<script>
function initializeLanguageSelector() {
    var selector = document.getElementById('languageSelector');
    var currentUrl = window.location.href;
    
    if (!currentUrl.includes('/tag/')) {
        var urlLanguage = currentUrl.includes('/ko/') ? 'ko' : 'en';
        localStorage.setItem('selectedLanguage', urlLanguage);
        selector.value = urlLanguage;
    } else {
        selector.value = localStorage.getItem('selectedLanguage') || 'en';
    }

    selector.style.display = 'block';

    selector.addEventListener('change', function() {
        localStorage.setItem('selectedLanguage', this.value);
        if (!currentUrl.includes('/tag/')) {
            window.location.href = this.value === 'ko' ? '/ko/' : '/';
        }
        else {
            window.location = window.location.href;
        }
    });
}

document.addEventListener('DOMContentLoaded', function() {
    initializeLanguageSelector();

    const selectedLanguage = getSelectedLanguage();
    if (selectedLanguage !== 'en') {
        updateLink('.gh-head-logo', selectedLanguage);
        updateLink('section.copyright a', selectedLanguage);
        updateLink('li.nav-home a', selectedLanguage);
    }
});
</script>
```

# Wrapping up

With this approach, it would even be possible to completely replace the block "lang" approach. Even so, I decided to keep the block "lang" approach as is, because from an SEO perspective it has the advantage that the html lang attribute is rendered server-side, and because I do not think this part is all that important.