Skip to content

Ghost Inline Stocks: add stock quotes to Ghost posts

By Ahmad Ajmi

When a post mentions Apple’s stock symbol, $AAPL, readers may want to see its price. Ghost Inline Stocks adds a small quote beside the symbol. It shows a price in US dollars and a percentage change within the paragraph.

I made this free script so you can add the feature to your Ghost theme without editing theme files.

I also include this feature in two of my Ghost themes: Siwa and Taba. If you use either, follow its own guide: Siwa or Taba.

A simple paragraph showing Apple, Microsoft and Tesla with prices and percentage changes
A paragraph with inline quotes for Apple, Microsoft and Tesla. These are example prices, not current market data.

Get a Finnhub key

The script is free. Its quotes come from Finnhub. You need a Finnhub account and an API key. This code lets the script request quotes.

  1. Create or log in to your Finnhub account.
  2. Open the Finnhub dashboard.
  3. Copy your API key.

Check Finnhub’s current plans and limits. Check which stocks you can access and whether you may publish their quotes. Then choose one of the two setup options below.

Choose a setup

Complete one of the two options below, then continue to Add the Script.

Direct setup

This is the quickest option. Anyone who views your site’s code can see your Finnhub key.

  1. In Ghost, open Settings → Advanced → Code Injection.
  2. Paste this snippet into Site Header.
  3. Replace YOUR_FINNHUB_KEY with your key.
  4. Select Save.
<script>
  window.finnhubApiKey = 'YOUR_FINNHUB_KEY';
</script>

This option keeps your Finnhub key in your Cloudflare account, out of your site’s code. You need a Cloudflare account and your Finnhub API key. Your website can stay on its current host.

  1. Open the stock ticker setup.
  2. Connect your Cloudflare account.
  3. Enter your website address and Finnhub API key.
  4. Copy the snippet shown during setup.
  5. In Ghost, paste it into Settings → Advanced → Code Injection → Site Header.
  6. Select Save.

If you switch from direct setup, remove the direct-key snippet. To add a site or update your key, run setup again with the same Cloudflare account.

Add the script

After completing either setup option, paste this into Site Footer and select Save:

<script
  src="https://cdn.jsdelivr.net/gh/aspirethemes/ghost-inline-stocks@main/dist/inline-stocks.min.js"
  defer
></script>

The script works on Ghost posts. It leaves the homepage, tag pages, author pages, and regular pages unchanged.

Check a post

Write this in a normal paragraph, then open the post preview or its web page:

Following $AAPL and $MSFT this week.

Each supported symbol should show a price in US dollars. It should also show the percentage change from the last closing price. Quotes load when the post opens. They do not keep updating.

Use uppercase US stock symbols of one to five letters, with a dollar sign before them. Symbols with extra parts, such as $BRK.B or $VOD.L, stay as plain text.

Symbols in headings, links and code blocks stay unchanged. The script adds quotes to the web page. It does not add them to Ghost newsletter emails.

If a symbol stays unchanged:

  1. Check that you saved the setup snippet in Site Header and the script in Site Footer.
  2. Check that the symbol is uppercase and appears in a normal paragraph.
  3. For direct setup, check that you replaced YOUR_FINNHUB_KEY with your key. For Cloudflare setup, check your website address. It must match the address readers visit.
  4. Wait a minute and reload. The account may have reached its quote-request limit. Try $AAPL as well. If it loads but another symbol does not, ask Finnhub support whether your plan covers that symbol.

If quotes still do not appear, contact me. Include your theme name, the post’s address and the stock symbol. Do not include your API key in the message. The original symbol stays readable when a quote cannot load.

Remove the feature

To turn off the feature, delete the Inline Stocks script from Site Footer and save. You can also remove the setup snippet from Site Header, if no other stock feature uses it. Keep any other code in both fields. Your posts still contain the original symbols. You do not need to rewrite your posts.

More from the Blog

Latest Ghost Themes