Custom HEAD Tags

Available in Grow Projects

Apply project-wide javascript, styles, links, and meta that gets added to the HEAD tag of the page.

Customising HEAD Tags

To customise HEAD tags:

  • Open Project Settings from the Sidebar.
  • Under External Integrations, select Custom HEAD Tags
  • Enter the custom tags as you would in HTML, and click Save. This will save the HTML in draft mode, so you can test it out.
  • To publish it to readers, click Save & Publish.
  • To revert the draft changes, click Revert.

All custom tags will only run in live mode, and will not load in editor mode.

Tags Format

Tags should be added fully as they would exist in HEAD, such as:

HTML
Copy

Do not add any <body>, <html> or other tags that do not naturally exist in HEAD.

Do not use async or defer in your scripts. Scripts will be loaded async regardless.

To ensure compatibility with all browsers, do not add any scripts that contain any syntax that is not supported by ECMAScript 5 (ES5, ECMAScript 2009). We do not automatically check or compile into ES5. Failure to do so may render your site unusable to some or all users.

Why add scripts?

By adding scripts, you can do more with your documentation:

  • Install third party services for tracking, analysing, interacting with your readers.
  • Create scripts that interact with Custom HTML in the pages or Custom Landing Page.
  • Add javascript redirection rules.
  • Add your own icon set using CSS.
  • Enhance your SEO by adding the relevant META tags to your business.
  • Change the UI Text.

External Hooks

There are several events that are triggered by DeveloperHub which can help you achieve the level of customisation you need. The full list of hooks is available at Javascript Dispatched Events.

Project Loaded

To listen to when a project loads, which is also when most elements of the page also are loaded, you may listen to a custom event on document called onprojectloaded. An example:

Markup
Copy

If you are aiming at modifying the top navigation, then you should use this event.

Because DeveloperHub is a single page application, document.onload has no effect in Custom HEAD tags. All Custom HEAD tags are actually loaded after document.onload is called. Use onprojectloaded whenever you need to use document.onload.

Section Changes

To listen to when a section (landing page, documentation) changes, you may listen to a custom event on document called onsectionchange. An example:

Markup
Copy

If the section changed is a documentation, then the indices are also listed.

Page Changes

To listen to when a page changes, you may listen to a custom event on document called onpagechange. An example:

Markup
Copy

Redirection Rules

Using Custom JS, you can setup front-end redirection rules. For example, if you want to redirect one of your projects which has semantic versioning less than 1.0 to another, you might want to use something like this:

Markup
Copy

Or if you have changed a documentation slug, then you might want to redirect to the new slug:

Markup
Copy

If you need more powerful redirection rules, then check server-side 301 redirect rules.

Custom Landing Page Loaded

See Custom Landing Page.

Staging Environment

There is no staging environment for testing HEAD tags changes at this moment. However, you can set up a new project and test the HEAD tags on it before applying it on your production project. Let us know if you needed help in setting up the project.

Disabling HEAD Tags

For testing if a script or style in HEAD tags is causing issues, you might want to disable all HEAD tags momentarily only for your browser. To do this, append a query ?disableScripts=true to any published docs URL.

For example, if your docs are available on https://example.com/docs then you can disable HEAD tags for your session using https://example.com/docs?disableScripts=true.

Once you refresh the page without disableScripts=true, HEAD tags will be enabled again.

Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard
  Last updated by Zaid Daba'een
customisation