replace_first

Replace only the first occurrence of a specified substring with a replacement string.

Syntax

{{ string | replace_first: substring, replacement }}

Example

{% assign title = "Spring Sale Spring Specials" %}{{ title | replace_first: "Spring", "2026 Spring" }}

Output

2026 Spring Sale Spring Specials

The replace_first filter substitutes only the very first occurrence of a matched pattern with a new string, leaving any subsequent instances untouched. It is well suited for modifying introductory phrases without altering body text.

In programmatic SEO campaigns, replace_first prefixes the initial mention of a keyword with fresh qualifiers or campaign tags. For example: {{ row.hero_title | replace_first: row.keyword, 'Top Rated ' | append: row.keyword }}. This introduces dynamic marketing qualifiers into page headings without distorting secondary keyword occurrences down the page.

Try this syntax in the editor.