Implement in-website edit button with the REST API

You can display an edit button on your live website only for your writers, so they can easily jump from the live website to the writing room to edit a page.

Before configuring an edit button, make sure that your site is configured for previews. It is a requirement for the edit button functionality.

Include the Prismic Toolbar javascript file

You will need to include the Prismic toolbar scripts on every page of your website. This means including it on your 404 page! 

You can find this script in your repository 'Settings' section, under the 'Previews' tab.

Settings > Previews > Script

If in the URL of the Prismic Toolbar script, that you copied from the Previews page of your repository, finishes with ?new=true like the script below. Then you are finished you don't need to read any further.

Copy
<script type="text/javascript" src="https://static.cdn.prismic.io/prismic.min.js?new=true"></script>

If your <script> has the URL below then keep reading.

Copy
<script type="text/javascript" src="https://static.cdn.prismic.io/prismic.min.js"></script>

Note: This edit button will only appear for Admins, Editors and Content Creators, to allow to easily edit your pages. It won't appear for standard website visitors or give them any access or control.

Include your document ids

Where you want to have an edit button inserted, add a data-wio-id attribute to the DOM container corresponding to your document. You can have several edit buttons in the same page.

Copy
<article data-wio-id="{insert document id}">
(...)
</article>

The prismic toolbar will add a link inside the tag, you're free to style it as you want to integrate it in your design.