👋 Next.js Conf 2024: Come build, party, run, and connect with us! See all events

How to Add Scripts to the Header of the Sanity Studio

3 replies
Last updated: Nov 13, 2020
Hi out there! I am trying to add a script to the header of the sanity studio, but i can’t seem to find where i can make additions to the <head> element. Can anyone point me in the right direction!
Nov 12, 2020, 8:43 AM
You can override Document.js (https://github.com/sanity-io/sanity/blob/next/packages/@sanity/base/src/components/Document.js#L54 ).

{
  "implements": "part:@sanity/base/document",
  "path": "components/Document.js"
}
You need to compile the jsx yourself if you override this thing. I've used parcel to do this, but you can use webpack or rollup as well.


parcel build src/Document.js --out-dir lib/
If you do this you get cut off from any future updates to Document.js though, so you should be careful. You could avoid this by using something that's present on all pages, and overwrite that, instead of the complete document. I've found that overriding the logo (
sanity init plugin -> Studio logo
) is the easiest way to load something on every page - so you might be better off using something like that. But that may be the hacker in me speaking.
Nov 12, 2020, 8:57 AM
user B
The hacker in you speaking, speaks to me! I just couldn’t find the entry point. This is what I needed. Many many thanks to you!!!
Nov 12, 2020, 9:15 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?