Trims leading/trailing whitespace and collapses internal whitespace runs (including tabs and non-breaking spaces) in product titles.
async def run(ctx): for product in await ctx.shopify.query(ALL_PRODUCTS): clean = collapse_whitespace(product.title)
How do you clean up whitespace in Shopify product titles?
To clean up whitespace in Shopify product titles, this template trims leading and trailing spaces and collapses internal runs, including tabs and the non-breaking spaces that ride along with copy-pasted supplier text. Those characters are invisible in the admin and poisonous everywhere else: a trailing space makes two identical titles sort apart, breaks exact-match searches, and splits what should be one deduplicated feed row into two. Word processors and PDFs are the usual source, which is why supplier-imported catalogs have it worst.
Nobody audits for characters they cannot see. The trimmer checks every active title in a single pass and touches only the ones that need it, which on most catalogs is a surprisingly long list the first time. Each affected title appears in the run report with the change made visible, and after the first cleanup the scheduled re-run keeps new imports honest.
Last updated August 24, 2026
If you run a sharper version of this template, or something it inspired, send it in. We review every application and publish the good ones, credited to you or your agency.
AI writes real Python or TypeScript, a dry run rehearses it, you approve, it deploys.
Free plan · no card · 🇪🇺 EU data residency