How can I add a 'scroll to top' button in my theme?

Topic summary

A user wants to add a scroll-to-top button to their Shopify theme, referencing a specific button element shown in an attached screenshot.

Current Issue:

  • The button is currently grayed out and non-functional
  • Attempting to link it to a page produces an error: “online store editor session can’t be published”
  • The user is comfortable with complex code solutions

Proposed Solutions:
Two support teams (GemPages and PageFly) provided similar implementation approaches:

  • Add custom code to the theme.liquid file
  • Insert the code snippet above the </body> tag (GemPages) or </head> tag (PageFly)
  • Access via: Online Store > Themes > Edit code

Both responses include code snippets and step-by-step instructions, though the exact code content appears corrupted or encoded in the original posts. The discussion remains open with no confirmation of which solution was implemented or successful.

Summarized with AI on November 22. AI used: claude-sonnet-4-5-20250929.

Hi,

I am trying to add a scroll to the top button to this button when you press it.

What code do I need to do this? It’s okay if it’s complex, I’m not a complete newbie with coding.

Also, is it going to be a problem if the button doesn’t link to anything. Because it’s greyed out right now and you can’t press it. I’ve tried linking it to a page and I get an error saying ‘online store editor session can’t be published.’

My product page is https://basicallysuperhuman.com/products/train-like-a-superhero-ebook

Thank you!

Hello @BasicallySuper ,

It’s the GemPages Support Team and we are glad to assist you today!

I would like to give you the recommendation to support you so kindly follow the steps below:

  1. Go to Online Store > Theme > Edit code of your current theme

  1. Open your theme.liquid theme file

  2. Paste the below code before


Let us know how it works for you.

Best regards,

GemPages Support Team

Hi @BasicallySuper

This is Victor from PageFly - Shopify Page Builder App

Please add this code to your theme.liquid above the to get this solved

Step 1: Online Stores > Themes > More Actions > Edit code

Step 2: click on theme.liquid and paste the code above the


Hope this can help you solve the issue

Best regards,

Victor | PageFly