Skip to content

Celebrating our new site: 30% off everything with code , until Dec 1.

Bright Themes

How to use snippets in Ghost

Save any part of a post as a snippet, from a line of text to a styled HTML card, and add it to any other post in a few keystrokes.

Norbert5 min read

A snippet is a part of a post you save in Ghost’s editor and reuse in other posts and pages: a paragraph, a sign-off, an image, an embed, or any of the editor’s cards, HTML cards included. Snippets are saved for the whole site, so everyone on your staff who writes sees the same list.

This tutorial covers saving, adding, replacing and deleting snippets, and what each does to the posts that already use one.

What you need

  • A login to Ghost Admin. Who can do what depends on the staff role:
    • Owner, Administrators and Editors can save, replace and delete snippets.
    • Authors and Contributors can add saved snippets to their posts, but can’t save new ones or change the list.
  • A post or page open in the editor, with the content you want to save.

Snippets live in the editor: there is no separate page for them in Settings. You save, add, replace and delete them while you write.

1. Save a snippet

You can save text and cards together, or one card on its own.

Text, or text with cards:

  1. Select the content you want to save, as you would to make it bold.
  2. In the toolbar that appears over the selection, choose the snippet icon (its tooltip is Save as snippet).
  3. Type a name in the Snippet name field.
  4. Press Enter, or choose Create ”…” under the field.

One card:

  1. Select the card, so its toolbar shows above it.
  2. Choose Save as snippet in the card’s toolbar.
  3. Type a name and press Enter.

Ghost confirms with “Snippet saved as” and the name. The snippet is now in the list for every post and page on the site.

2. Add a snippet to a post

Snippets sit in the card menu, in their own Snippets section, under the cards.

  1. Start a new, empty line in the post.
  2. Type / and then the snippet’s name, for example /newsletter sign-off. The menu filters as you type.
  3. Press Enter, or choose the snippet in the menu.

You can also open the card menu with the + button at the start of an empty line, and scroll to Snippets. Typing /snippets lists them all.

The snippet goes in where your cursor was, and you can change it like any other content.

3. Update a saved snippet

There is no edit screen for a snippet. To change one, you save new content under its name, and it replaces the old version.

  1. Add the snippet to a post (step 2) and make your changes, or write the new version from scratch.
  2. Select it, and choose Save as snippet, as in step 1.
  3. Start typing the snippet’s name. Under Replace existing, choose it.
  4. Ghost asks Update this snippet?. Choose Update.

If you type a name that’s already taken and press Enter, Ghost asks the same question, so you can’t overwrite a snippet by accident.

4. Delete a snippet

  1. On an empty line, type / and the snippet’s name, or open the card menu and scroll to Snippets.
  2. Hover over the snippet and choose the trash can icon.
  3. Ghost asks you to confirm. Choose Delete snippet.

Deleting is permanent and removes the snippet for all staff users.

What happens to posts that already use it

Each time you add a snippet, Ghost puts a copy of its content into the post. The post doesn’t keep a link to the snippet.

  • When you update a snippet, only the posts you add it to from then on get the new version. Posts that already have it stay the same.
  • When you delete a snippet, posts that use it don’t change.
  • When you edit a snippet’s content in one post, only that post changes.

So a snippet is a template, not a shared block. To change something in every post at once, the change has to live outside the posts, which is what the next tip is about.

Tips

  • Name snippets so the list sorts well. The menu lists them A to Z, and you find them by typing. A shared first word groups them: “CTA: newsletter”, “CTA: book a call”, “Box: key takeaways”.
  • Keep the styles in code injection. A snippet made from an HTML card copies its HTML into each post. If the card carries its own <style> tag, every post gets its own copy of the CSS, and a later change means editing every post. Put the CSS once in Settings › Advanced › Code injection › Site header instead, and keep only the HTML in the snippet. Change the CSS there, and every post that uses the snippet follows. How code injection works in Ghost shows where it goes.

Our ready-made snippets

We publish snippets that follow those tips: in all but one, the HTML goes in an HTML card and the CSS in code injection, once per site. Each page has the code and the steps to save it as a snippet.

  • Accordions: collapsible sections for FAQs and long posts.
  • Alert boxes: note, info, warning, danger and success boxes, each with its own icon.
  • Progress cards and steps: a percentage bar and a numbered step list, for course progress or a how-to.
  • Schema markup: recipe structured data (JSON-LD) for a post, so search engines can show it as a rich result. It has no CSS.
  • Subscribe forms: a sign-up form inside a post, where readers choose their topics.
  • Tables: comparison and rating tables that scroll sideways on phones.
  • Key takeaways: a box at the top of a post with the main points.
  • Pros and cons: two lists side by side, with ticks and crosses, for reviews.
  • Guest bio box: the guest’s photo, name, role and links, for the end of a guest post.

They’re all on Ghost snippets.

Snippets or widgets

We also publish widgets, such as a table of contents or a back-to-top button. A widget is different: you set it up once in code injection, and it runs on every post by itself. There is nothing to save as a snippet and nothing to add to each post. Use a snippet for content you place by hand in some posts, and a widget for something every post should have.

The result

Your reusable content is a few keystrokes away in every post, the styles live in one place for the whole site, and you know that updating or deleting a snippet leaves your published posts as they are.

Related posts

More on editor

Get the Bright Themes newsletter

New tutorials and explainers, what changed in Ghost, and our theme releases. No spam, unsubscribe anytime.

Get the Bright Themes newsletter

New tutorials and explainers, what changed in Ghost, and our theme releases. No spam, unsubscribe anytime.