Substitutions
Substitutions automatically find a piece of text and replace it with different text every time your project publishes, perfect for swapping staging URLs for production URLs, fixing a recurring typo, or updating a brand name across your whole site at once.
Where to find it
- Open your project.
- Go to Project Settings.
- Scroll to the Substitutions section.
How it works
Each substitution is a simple rule with two parts:
- Enter text to replace: the exact text to search for.
- Enter replacement text: the text to swap it with.
When you publish, WCH scans your published pages and replaces every occurrence of the find text with the replacement text. A few things to know:
- Exact text match, not a pattern. The find text is matched literally. There are no wildcards or regular expressions. What you type is exactly what it looks for.
- Case-sensitive.
Homeandhomeare treated as different text. A rule forHomewill not affecthome. - Replaces every match. All occurrences are replaced, not just the first one.
- Applies to your HTML pages. For a normal publish (a single page, or Publish All), substitutions run on your published HTML files.
When substitutions run
Substitutions are applied automatically during publishing. You don't trigger them separately. Set the rules once and they apply on every publish going forward, including:
- Publishing a single page or asset
- Publish All (a full project publish)
- Push to production
- CMS-triggered publishes
Adding a substitution
- In the Substitutions section, click Add substitution.
- In Enter text to replace, type the exact text you want to find.
- In Enter replacement text, type what it should become.
- Save. The rule takes effect on your next publish.
You can add as many rules as you need. Each one is listed with its find and replace values, and you can delete a rule at any time.
Testing your rules
Because substitutions change your live output, it's wise to test before a full publish:
- Add or edit the rule.
- Publish a single page first and check that the result looks right.
- Once you're confident, use Publish All.
If a substitution produces an unexpected result, delete or narrow the rule and republish.
—
⚠️ Keep your rules as specific as possible
Because a substitution replaces every matching occurrence across all your pages, an overly broad rule can change text you never intended to touch. For example, a rule that replaces link or the would match those letters inside countless words and quietly corrupt your pages.
To avoid unintentional replacements:
- Match the longest, most unique string you safely can. Prefer
https://staging.example.com/over juststagingorexample. - Include surrounding context so the text can't match somewhere unexpected, for instance, replace
"oldbrand.com"(with the quotes or a leading slash) rather than the bare wordoldbrand. - Avoid short or common words like
home,the, or single characters. They will match far more than you expect. - Remember it's case-sensitive. If your target text appears in different capitalizations, you may need a separate rule for each.