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 SpecialsThe 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.
Filters
- abs
- append
- at_least
- at_most
- capitalize
- ceil
- compact
- concat
- date
- default
- divided_by
- downcase
- escape
- escape_once
- first
- floor
- join
- last
- lstrip
- map
- minus
- modulo
- newline_to_br
- plus
- prepend
- remove
- remove_first
- replace
- replace_first
- reverse
- round
- rstrip
- size
- slice
- sort
- sort_natural
- split
- strip
- strip_html
- strip_newlines
- times
- truncate
- truncatewords
- uniq
- upcase
- url_decode
- url_encode
- where
- raw
- slugify
- number_format
