Can the "Publish" button text be changed to "Save" in Sanity.io?

6 replies
Last updated: Jun 21, 2023
Change the "Publish" button text to "Save"??Any quick tips on how to?
AI Update

You can customize the "Publish" button text by overriding the default PublishAction in your Studio configuration. Here's how to do it:

First, create a custom document actions resolver. In your Studio config folder, create a file (e.g., customDocumentActions.ts or customDocumentActions.js):

import {PublishAction} from 'sanity'

// Custom publish action with different label
const CustomPublishAction = (props) => {
  const defaultPublishAction = PublishAction(props)
  
  return {
    ...defaultPublishAction,
    label: 'Save' // Change the button text here
  }
}

export default function resolveDocumentActions(props) {
  // Replace the default PublishAction with your custom one
  return [CustomPublishAction]
}

Then, add this resolver to your sanity.config.ts:

import {defineConfig} from 'sanity'
import {structureTool} from 'sanity/structure'
import resolveDocumentActions from './customDocumentActions'

export default defineConfig({
  // ... other config
  document: {
    actions: resolveDocumentActions
  }
})

If you want to keep all the other default actions (like Unpublish, Delete, etc.) alongside your custom "Save" button, modify the resolver like this:

import {PublishAction} from 'sanity'
import defaultResolve from 'sanity'

const CustomPublishAction = (props) => {
  const defaultPublishAction = PublishAction(props)
  return {
    ...defaultPublishAction,
    label: 'Save'
  }
}

export default function resolveDocumentActions(props) {
  return defaultResolve(props).map((Action) =>
    Action === PublishAction ? CustomPublishAction : Action
  )
}

This approach lets you customize document actions while maintaining all the built-in functionality of the publish action—just with different button text!

Hey (Removed Name),
I don't think that it's possible at this time, as it looks like
Publish
is hardcoded .
Ah that's a shame!
Our problem is that we have to manually trigger a build with getStaticProps (next.js), so "publish" in sanity is a bit misleading for our users
🤷‍♂️
Hoping this might change in the future!
Ahh, I understand. Sorry about that! I will definitely pass this along, as we've had a few similar requests recently.
Thanks a bunch, and great to hear we're not alone!
Hey (Removed Name), I passed it along, and I stand corrected!
It is possible to make this change, and I received this snippet:


function renamePublishAction(originalPublishAction) {
  return (props) => {
    const originalResult = originalPublishAction(props);
    return {
      ...originalResult,
      label: 'Save',
    };
  };
}

// ...

export default defineConfig({
  actions: (prev) =>
    prev.map((originalAction) =>
      originalAction.action === 'publish' ? renamePublishAction(originalAction) : originalAction
    ),
  // ... rest of config ...
});
Haha! Great news!!
Tried it and works great, with this little edit (
actions
goes in
document
):
export default defineConfig({
  document: {
    actions: (prev) =>
      prev.map((originalAction) =>
        originalAction.action === 'publish' ? renamePublishAction(originalAction) : originalAction
      ),
  },

  // ...rest of config
})

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?