Articles on: KoalaLinks

KoalaLinks Code Snippet and Configuration

The KoalaLinks snippet places your analyzed internal links, related posts and schema on your live pages. Install it once per site. It loads with defer and is served from a global cache, so it doesn't hold up your page.


Install the snippet


  1. Open your site in KoalaLinks.
  2. Click Snippet.
  3. In the Embed Code window, click Copy Code.
  4. Paste the code into your site's HTML.


Most platforms let you add custom HTML to the header or footer, and either location works. On WordPress, install the free WPCode plugin, paste the code in its Header section and click Save. Load the snippet only once per page.


The copied code looks like this, with your site's ID in place of DOMAIN_ID:


<script>
window.KoalaLinksConfig = {};
var script = document.createElement("script");
script.defer = true;
script.src = "https://koala.sh/api/eucalyptus.js?domainId=DOMAIN_ID&page=" + encodeURIComponent(window.location.protocol + "//" + window.location.host + window.location.pathname);
document.head.appendChild(script);
</script>


Turn features on or off without code


The Settings tab on your site's KoalaLinks page has a switch for each feature: Entity schema (auto-generated), Schema rules, Per-URL custom schemas, Internal links and Related posts. These apply to every page on the site, and you don't need to edit the snippet.


The snippet's data is cached for up to an hour. Click Force cache refresh on the Settings tab to push changes sooner.


Configure the snippet


For page-level control, add options inside window.KoalaLinksConfig = {} in your snippet. Anything you set replaces the default for that option. Here's a full snippet that changes the "RELATED" label to "Related:" (keep your own domain ID):


<script>
window.KoalaLinksConfig = {
inlineRelatedPostTemplate: `
<div class="kl-inline-related-post">
<span class="kl-related-post__title">Related:</span>
<a class="kl-related-post__link" href="{{url}}">{{title}}</a>
</div>
`,
};
var script = document.createElement("script");
script.defer = true;
script.src = "https://koala.sh/api/eucalyptus.js?domainId=DOMAIN_ID&page=" + encodeURIComponent(window.location.protocol + "//" + window.location.host + window.location.pathname);
document.head.appendChild(script);
</script>


The examples below show only the window.KoalaLinksConfig part.


Point the snippet at your article content


The snippet tries .entry-content, .elementor-widget-theme-post-content, .woocommerce_archive_description, main and article in that order, and uses the first selector that matches exactly one element. If none match, it picks the section with the most paragraphs and headings. If links land in the wrong place, give it your content wrapper. For <div class="main-content">:


window.KoalaLinksConfig = {
articleSelector: [".main-content"]
}



By default the list goes at the end of .entry-content or .elementor-widget-theme-post-content, whichever matches exactly one element first. To place it inside <div class="related-posts">:


window.KoalaLinksConfig = {
relatedPostListTargetSelector: [".related-posts"]
}


Change how many posts the list shows with relatedPostListCount (default 5).



Inline related posts go before each H2 by default. To use H2s and H3s:


window.KoalaLinksConfig = {
relatedPostInsertBeforeSelector: "h2, h3"
}


To skip the first few headings, set relatedPostSkipCount (for example 1 skips the first H2).



excludeLinksTo drops any internal link or related post whose URL contains one of the strings you list:


window.KoalaLinksConfig = {
excludeLinksTo: ["/contact/", "/tag/"]
}


Turn off a feature on specific pages


Each of these turns off one feature wherever this snippet runs:


window.KoalaLinksConfig = {
enableInternalLinks: false,
enableInlineRelatedPosts: false,
enableRelatedPostsAtBottom: false,
enableSchema: false
}


Use only the lines you need.



window.KoalaLinksConfig = {
openLinksInNewTab: true
}


Add your own styles


extraCss is added after the default styles, so you can restyle the related posts without replacing them:


window.KoalaLinksConfig = {
extraCss: ".kl-related-post__title { color: #2563eb; }"
}


Default configuration


These are the main defaults in the current snippet. Any option you leave out keeps its default.


{
enableInternalLinks: true,
enableInlineRelatedPosts: true,
enableRelatedPostsAtBottom: true,
enableSchema: true,
autoRun: true,
openLinksInNewTab: false,
excludeLinksTo: [],
css: `
.kl-related-post__title {
font-weight: bold;
}

.kl-related-post-list__item {
margin-bottom: 10px;
}

.kl-related-post-list__container {
margin: 0;
}
`,
extraCss: "",
schemaId: "koalalinks-schema",
styleId: "koalalinks-styles",
articleSelector: [".entry-content", ".elementor-widget-theme-post-content", ".woocommerce_archive_description", "main", "article"],
relatedPostInsertBeforeSelector: "h2",
relatedPostSkipCount: 0,
inlineRelatedPostTemplate: `
<div class="kl-inline-related-post">
<span class="kl-related-post__title">RELATED</span>
<a class="kl-related-post__link" href="{{url}}">{{title}}</a>
</div>
`,
relatedPostListTargetSelector: [".entry-content", ".elementor-widget-theme-post-content"],
relatedPostListCount: 5,
relatedPostListTemplate: `
<div class="kl-related-post-list">
<h3 class="kl-related-post-list__header">Related Posts</h3>
<ol class="kl-related-post-list__container">{{relatedPosts}}</ol>
</div>
`,
relatedPostListItemTemplate: `
<li class="kl-related-post-list__item">
<a class="kl-related-post-list__link" href="{{url}}">
{{title}}
</a>
</li>
`,
enableClickAnalytics: true
}


The snippet never inserts links inside existing links, headings, buttons, form fields, code blocks, images, video or other embedded media.



Check these first:


  • The page has been analyzed in KoalaLinks (its Analyzed column shows when).
  • The feature is switched on in the Settings tab.
  • Your browser console shows KoalaLinks: Initialized. A KoalaLinks: Already loaded error means the snippet is on the page twice.


If it still doesn't work, contact support with a URL where the snippet is installed.

Updated on: 09/11/2026

Was this article helpful?

Share your feedback

Cancel

Thank you!