WordPress · Drupal · Site Maintenance · Technical SEO · Editorial Policy

How to Find and Remove Injected Code on a Shopify Site

Shopify runs and patches the platform itself, so there is no server, no PHP and no core to clean. Unwanted code on a Shopify store almost always sits in one of a few places you control: theme files, installed apps, third-party scripts and tracking pixels, or content fields that accept HTML. A staff account with stolen or weak credentials is the usual way it gets there. This guide shows where to look, how to remove it, and how to stop it returning.

Where injected code can live on a Shopify store

Shopify is a hosted platform, so your search area is smaller than on a self-hosted site. Check these places in turn:

  • Theme files: theme.liquid, templates, sections, snippets and assets (JavaScript and CSS).
  • App leftovers: apps often add snippets or script references to your theme, and uninstalling an app does not always remove them.
  • Custom pixels and tracking: configured under Settings, in Customer events.
  • Content fields: pages, blog posts, product descriptions and metafields that accept HTML.
  • Staff accounts: anyone who can edit theme code or install apps.

Typical symptoms include visitors being sent to another site, unfamiliar links hidden in the footer or in invisible elements, pop-ups you did not create, and scripts loading from domains you do not recognise.

Start with a safe copy

Before you change anything, make a backup. In your admin, open Online Store, then Themes. Use the theme’s actions menu to duplicate the live theme. Work on the duplicate, and keep the original untouched until you have confirmed what is wrong.

If you suspect a compromised account, change access first (see the credential section below). Otherwise someone can re-add the code while you clean.

Compare your theme against a known-clean version

Comparison is the fastest way to spot code nobody on your team wrote. You have several sources for a clean reference:

  1. The original theme. If you bought or installed your theme from the Shopify Theme Store, download a fresh copy of the same theme and compare it to your live files.
  2. Your own version control. If your theme is connected to a Git repository, or you keep one, compare the live files with the last commit you trust. Shopify’s theme library supports connecting a theme to GitHub, and Shopify CLI can pull a theme to your computer.
  3. An older theme version. A previous duplicate or backup of the theme that you know was healthy.

Pull both copies into a local folder and run a diff with any file comparison tool. Pay attention to additions near the top or bottom of theme.liquid, in the head, and in JavaScript files under assets. The Shopify developer documentation on themes explains the file structure so you know what each file is for: Shopify theme documentation.

Search your code for suspicious patterns

If you have no clean copy, search instead. In the theme code editor, use the search across files. If you have pulled the theme locally, use your editor’s project-wide search. Look for:

  • <script tags with an src pointing to a domain you do not recognise.
  • eval(, atob(, unescape( and long strings of encoded characters, which are common ways to hide script contents.
  • document.write and window.location assignments that you did not add.
  • Links inside elements styled with display:none, tiny font sizes or off-screen positioning, which is how hidden links are usually concealed.
  • <iframe and <meta http-equiv="refresh" elements.

Not everything that matches is malicious. Analytics, chat widgets and review apps legitimately load external scripts. For each hit, ask what it does, which app or person added it, and whether you still use that service. If you cannot answer, treat it as suspect.

Review apps, embeds and pixels

Third-party code often arrives through places other than the code editor. Work through this checklist:

  • In the admin, open the list of installed apps and uninstall any you do not recognise or no longer use.
  • In the theme editor, open the app embeds area and switch off any embed you do not need.
  • Under Settings, open Customer events and review every custom pixel. Remove any you cannot attribute to a person or tool you trust.
  • Check the theme for leftover snippet files and script references from apps you have already removed.
  • Open pages, blog posts and product descriptions in their HTML view and look for script tags or unfamiliar iframes.

The Shopify Help Center covers apps, themes and store settings in one place: Shopify Help Center.

Remove the code and rotate credentials

Once you have identified the bad code, remove it from the duplicate theme, preview the result, and test the storefront, cart and checkout flow. Then publish the cleaned theme. Delete old copies of the theme that still contain the injected code, so nobody republishes one by mistake.

Cleaning without closing the entry point means it can come back. Do these steps in order:

  1. Review the staff list under Settings, in Users. Remove accounts that no one needs, and reduce permissions so only people who must edit theme code or install apps can do so.
  2. Require two-step authentication for every staff account that you can, and make sure the store owner account uses it.
  3. Reset passwords for all staff, and for any email account tied to a staff login. Use unique passwords stored in a password manager.
  4. Review any collaborator or agency access, and remove access for work that has finished.
  5. Regenerate or revoke API credentials and tokens that belong to custom apps or integrations you no longer trust.

Prevent injected code from coming back

A few habits make the next incident easier to spot and shorter to fix:

  • Keep your theme in version control and review changes before they go live, so every edit is visible in a diff.
  • Limit who can edit code. Use the narrowest permission that lets each person do their job.
  • Add apps and scripts deliberately. Keep a short list of what each one is for, and remove it when the need ends.
  • Audit on a schedule. Re-check pixels, app embeds and theme files whenever staff or agencies change.
  • Understand the attack type. Most storefront injection is a form of cross-site scripting or a compromised account. OWASP’s overview helps your developers understand how it works: OWASP cross-site scripting overview.

Frequently asked questions

Can Shopify itself be hacked so my theme gets infected?

Shopify maintains the platform, so you do not patch servers or core software. Problems on a store usually come from what you control: staff credentials, installed apps, third-party scripts and theme code. If you suspect something at platform level, contact Shopify support.

Will deleting an app remove its code from my theme?

Not always. Some apps leave snippets, asset files or script references behind. After uninstalling, search your theme for the app’s name and for its script domains, and remove what is left once you are sure nothing else depends on it.

Do I need a developer to clean this up?

Not for the first steps. Duplicating the theme, reviewing apps and pixels, and tightening staff access are all done in the admin. A developer helps when code is obfuscated, when you cannot tell what a file should contain, or when you want a proper Git workflow for your theme.

We use essential cookies to make this site work and remember your preferences. We do not use advertising or analytics cookies. Privacy Policy. Cookie Policy.