Shopifyのブログ記事内に自動で目次を生成する Tsun Inc.

Automatically generate a table of contents in Shopify blog posts

小笠原 京平

This is the only Shopify app in the world that can automatically generate tables of contents not only for blog articles, but also for product pages, collections, Pages, etc.
It is available for free and can be implemented with no code.
Various customizations are possible, including wording, design, scrolling on/off, and adjusting the display position of the table of contents. In addition, the live preview function allows you to customize the table of contents while checking it in real time.

Why did you decide to make it?

  • A table of contents is essential for the readability of blog posts.
  • It is not possible to generate a table of contents with the native Shopify CMS
  • Even if you can generate a table of contents, manually inserting the table of contents for each article is time-consuming.

In the article below, we introduce an app that generates a table of contents for Shopify, so please use it as a reference.

Introducing a Shopify app that can generate a table of contents

If you haven't used Shopify's blogging feature yet, please refer to the article below that explains Shopify's blogging feature.
Take full advantage of Shopify's blogging features | Introducing features and extension apps

What you created

I created a script that automatically generates a table of contents by extracting the h2 and h3 tags in Shopify blog articles.
You can generate a table of contents like this.

Reference example of generated table of contents

The main functions are as follows.

  • Automatically generate table of contents based on h2 and h3 tags in blog articles
  • Runs the script within the theme, so it is reflected in every blog post
  • Click on the table of contents to scroll to the relevant section

Please see the full code in the Tsun Inc. repository.

We will explain the implementation method in detail below!

Before starting implementation (comparison of app and source code)

Before we start implementation, we have released a free table of contents creation app called "RuffRuff Table of Contents". Before starting implementation, try installing the app once to save implementation time for free.

Feature comparison between app and source code

App name RuffRuff Table of Contents Source code of this article
Automatic generation of table of contents ◯ ◯
Heading selection
(Use table of contents)
◯
h1~h6
✕
h2 and h3 only
scroll
(Smooth Scroll)
◯ ✕
Paragraph display ◯
3 types
✕
separator line ◯ ✕
indentation
(indent)
◯ ◯
color change ◯ ✕
open/close button ◯ ✕
Initial display line number setting ◯ ✕
Hide table of contents for specific articles ◯
Separate templates
✕
Adjusting the display position of the table of contents ◯
3 types
✕
only on the first heading
live preview ◯ ✕
to product page
Table of contents display
◯ ✕
to collection page
Table of contents display
◯ ✕
Pages
Table of contents display
◯ ✕

Prerequisites

Target audience

  • You can change the theme of Shopify
  • Have basic knowledge of HTML, CSS, and JavaScript

What to prepare

  • Dawn theme (Operation was confirmed with v5.0.0, but there should be no problem with previous versions.)
  • Blog article 

Implementation

*This implementation method involves directly editing the Shopify theme code, so be sure to make a backup beforehand.

In this implementation

  • Add a JavaScript file to automatically generate a table of contents
  • Enable the above JavaScript to be executed

There are two steps.

Both steps are performed from the code editing screen, so

  1. From the Shopify admin, go to Online Store > Themes and select the theme
  2. Actions > Edit code

Please do this and display the code editing screen.

Add a JavaScript file

  1. Assets > Select Add new asset
  2. Create an empty file
  3. Enter name: table-of-contents, file type: .js, and add the asset
  4. Select the table-of-contents.js created in the Assets list
  5. Paste the code and select Save

Allow JavaScript to run

  1. Select main-article.liquid from the Sections list
  2. Change the location where the content part of the blog article is inserted as below

Testing in the development environment

KOMARI's Local development environment for Shopify themes -Shopify CLI- The article is very helpful, so if you are interested in the test method, please check it out!

Summary

As mentioned above, we were able to automatically generate a table of contents by adding JavaScript code to the theme.

Please modify the design of the table of contents, the tags to be extracted, the IDs of the tags to be generated, etc., as appropriate, and use it as you like.

I created a free Shopify app "RuffRuff Table of Contents" that automatically generates a table of contents.

If you want to easily add an original design table of contents to your blog articles, please try it once.

[Free] RuffRuff Table of Contents

This is the latest Shopify app that was just released in December 2022.
It is available for free, and if it is a Shopify theme that is compatible with OS 2.0, it can be installed with no code.
Various customizations are possible, including wording, design, scrolling on/off, and adjusting the display position of the table of contents. In addition, the live preview function allows you to customize the table of contents while checking it in real time.

Fee

From $0/month

function

  •  Automatic generation of table of contents
  •  Select headings to use in the table of contents (from h1 to h6)
  •  Change title wording
  •  Change presence/absence of separator line
  •  Color change (background, frame, separator line, title, link)
  •  Change in chapter number notation (can be selected from 3 types: none, dots, and numbers)
  •  Change the presence or absence of indentation
  •  Change whether or not to scroll
  •  Adjusting scroll offset
  •  live preview

👆️目次はShopifyアプリ「RuffRuff 目次作成」を利用

👆️Table of contents by the Shopify app RuffRuff Table of Contents

Back to blog
  • Shopifyで使える決済方法一覧|手数料・導入サービス・選び方

    [Complete Guide] A Roundup of Payment Methods A...

    Tsunライターチーム

    This article gives a detailed explanation of the many payment methods available on Shopify and their respective payment processing fees and transaction fees. We also introduce handy Shopify apps that...

    [Complete Guide] A Roundup of Payment Methods A...

    Tsunライターチーム

    This article gives a detailed explanation of the many payment methods available on Shopify and their respective payment processing fees and transaction fees. We also introduce handy Shopify apps that...

  • GMOイプシロンの手数料・決済方法・入金サイクル|Shopifyの条件も解説

    GMO Epsilon Fees, Payment Methods, and Payout C...

    Tsun ライターチーム

    GMO Epsilon payment methods and fees, organized by contract type. Covers Shopify-specific terms, payouts, authorization and capture deadlines, refunds, and cancellation. Also introduces ways to use apps to control which...

    GMO Epsilon Fees, Payment Methods, and Payout C...

    Tsun ライターチーム

    GMO Epsilon payment methods and fees, organized by contract type. Covers Shopify-specific terms, payouts, authorization and capture deadlines, refunds, and cancellation. Also introduces ways to use apps to control which...

  • Shopify向けSBペイメントサービス|対応決済・手数料・導入時の注意点

    SB Payment Service for Shopify: Supported Payme...

    Tsun ライターチーム

    This article organizes the payment methods and pricing available with SBPS for Shopify. Compare cost estimates that include fixed costs, authentication fees, and Shopify fees, along with capture deadlines and...

    SB Payment Service for Shopify: Supported Payme...

    Tsun ライターチーム

    This article organizes the payment methods and pricing available with SBPS for Shopify. Compare cost estimates that include fixed costs, authentication fees, and Shopify fees, along with capture deadlines and...

  • KOMOJUとShopifyの連携|決済方法・手数料・オーソリ期限

    Integrating KOMOJU with Shopify: Payment Method...

    Tsunライターチーム

    This guide lists the KOMOJU payment methods available on Shopify and their fees. It covers rates for physical goods and digital content, additional Shopify fees, setup steps, authorization periods, payouts,...

    Integrating KOMOJU with Shopify: Payment Method...

    Tsunライターチーム

    This guide lists the KOMOJU payment methods available on Shopify and their fees. It covers rates for physical goods and digital content, additional Shopify fees, setup steps, authorization periods, payouts,...

  • Shopifyのセキュリティ対策|決済・アプリ要件・バグバウンティ

    Shopify Security: Payments, App Requirements, a...

    Tsun ライターチーム

    For businesses considering Shopify, this article explains security safeguards for communications, customer information, payments, and apps, along with third-party assessments. Review the scope of protection, compensation requirements, operational preparations, and...

    Shopify Security: Payments, App Requirements, a...

    Tsun ライターチーム

    For businesses considering Shopify, this article explains security safeguards for communications, customer information, payments, and apps, along with third-party assessments. Review the scope of protection, compensation requirements, operational preparations, and...

  • Shopifyサーバーの費用・稼働率・障害時の対処法

    Shopify server costs, uptime, and how to respon...

    Tsun ライターチーム

    Shopify web hosting is included in the plan fee. This article organizes costs and the scope of management, the difference between official uptime figures and contractual guarantees, the checks to...

    Shopify server costs, uptime, and how to respon...

    Tsun ライターチーム

    Shopify web hosting is included in the plan fee. This article organizes costs and the scope of management, the difference between official uptime figures and contractual guarantees, the checks to...

1 of 6
  • AI仮想顧客の改善ツール「SimGym」を使ったら売上はどうなった?実行から3か月後までの記録

    What Happened to Sales After Using SimGym, an A...

    テキサス・アユミ

    A record of trying SimGym on the miso specialty store ドットミソ, from checking the proposals through carrying out changes to the look-back three months later. It covers how the order...

    What Happened to Sales After Using SimGym, an A...

    テキサス・アユミ

    A record of trying SimGym on the miso specialty store ドットミソ, from checking the proposals through carrying out changes to the look-back three months later. It covers how the order...

  • 【ストアインタビュー後編】やりながら育てるShopify。「野菜をMOTTO」の試行錯誤:モンマルシェ株式会社 河野雄士さん

    [Store Interview, Part 2] Building and Growing ...

    テキサス・アユミ

    "Even when e-commerce is the main battlefield, e-commerce isn't the goal." An in-depth look at our interview with Yuji Kono of Mon Marché, whose brand "Yasai wo MOTTO" grew its...

    [Store Interview, Part 2] Building and Growing ...

    テキサス・アユミ

    "Even when e-commerce is the main battlefield, e-commerce isn't the goal." An in-depth look at our interview with Yuji Kono of Mon Marché, whose brand "Yasai wo MOTTO" grew its...

  • 【ストアインタビュー前編】 ECが主戦場でも、ECが目的ではない。「野菜をMOTTO」が貫くEC戦略:モンマルシェ株式会社 河野雄士さん

    [Store Interview, Part 1] Even When E-Commerce ...

    テキサス・アユミ

    "Even when e-commerce is the main battlefield, e-commerce isn't the goal." Part 1 of our interview with Yuji Kono of Mon Marché, whose brand "Yasai wo MOTTO" grew its e-commerce...

    [Store Interview, Part 1] Even When E-Commerce ...

    テキサス・アユミ

    "Even when e-commerce is the main battlefield, e-commerce isn't the goal." Part 1 of our interview with Yuji Kono of Mon Marché, whose brand "Yasai wo MOTTO" grew its e-commerce...

1 of 3
  • Our Editorial Process

    For readers new to e-commerce and Shopify, we write our articles with care to explain difficult commerce and marketing terms, along with how everything works from building a store through to selling, as “gently,” “clearly,” and “accurately” as we can.

    Learn more 
  • About the information on this site

    The information published here is based on Tsun Inc.’s own experience and research. While we make every effort to publish information that is as “current” and “accurate” as possible, we cannot fully guarantee its contents. Tsun Inc. accepts no liability whatsoever for any damages arising from this site. If you find an error in the information published here, we would be grateful if you would contact Tsun Inc.