append

Concatenates two strings and returns the concatenated value.
{{ "/my/fancy/url" | append: ".html" }}
/my/fancy/url.html
append can also be used with variables:
{% assign filename = "/index.html" %}
{{ "website.com" | append: filename }}
website.com/index.html

prepend

Adds the specified string to the beginning of another string.
{{ "apples, oranges, and bananas" | prepend: "Some fruit: " }}
Some fruit: apples, oranges, and bananas
prepend can also be used with variables:
{% assign url = "example.com" %}
{{ "/index.html" | prepend: url }}
example.com/index.html

capitalize

Makes the first character of a string capitalized.
{{ "title" | capitalize }}
Title
capitalize only capitalizes the first character of a string, so later words are not affected:
{{ "my great title" | capitalize }}
My great title

upcase

Makes each character in a string uppercase. It has no effect on strings which are already all uppercase.
{{ "Parker Moore" | upcase }}
PARKER MOORE
{{ "APPLE" | upcase }}
APPLE

downcase

Makes each character in a string lowercase. It has no effect on strings which are already all lowercase.
{{ "Parker Moore" | downcase }}
parker moore
{{ "apple" | downcase }}
apple

strip

Removes all whitespace (tabs, spaces, and newlines) from both the left and right sides of a string. It does not affect spaces between words.
BEGIN{{ "          So much room for activities!          " | strip }}END
BEGINSo much room for activities!END

lstrip

Removes all whitespace (tabs, spaces, and newlines) from the left side of a string. It does not affect spaces between words.
BEGIN{{ "          So much room for activities!          " | lstrip }}END
BEGINSo much room for activities!          END

rstrip

Removes all whitespace (tabs, spaces, and newlines) from the right side of a string. It does not affect spaces between words.
BEGIN{{ "          So much room for activities!          " | rstrip }}END
BEGIN          So much room for activities!END

strip_newlines

Removes any newline characters (line breaks) from a string.
{% capture string_with_newlines %}
Hello
there
{% endcapture %}

{{ string_with_newlines | strip_newlines }}
Hellothere

replace

Replaces every occurrence of the first argument in a string with the second argument.
{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}
Take your protein pills and put your helmet on

replace_first

Replaces only the first occurrence of the first argument in a string with the second argument.
{{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }}
Take your protein pills and put my helmet on

replace_last

Replaces only the last occurrence of the first argument in a string with the second argument.
{{ "Take my protein pills and put my helmet on" | replace_last: "my", "your" }}
Take my protein pills and put your helmet on

remove

Removes every occurrence of the specified substring from a string.
{{ "I strained to see the train through the rain" | remove: "rain" }}
I sted to see the t through the

remove_first

Removes only the first occurrence of the specified substring from a string.
{{ "I strained to see the train through the rain" | remove_first: "rain" }}
I sted to see the train through the rain

remove_last

Removes only the last occurrence of the specified substring from a string.
{{ "I strained to see the train through the rain" | remove_last: "rain" }}
I strained to see the train through the

truncate

Shortens a string down to the number of characters passed as an argument. If the specified number of characters is less than the length of the string, an ellipsis (…) is appended to the string and is included in the character count.

Basic Usage

{{ "Ground control to Major Tom." | truncate: 20 }}
Ground control to...

Custom ellipsis

truncate takes an optional second argument that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (…), but you can specify a different sequence. The length of the second argument counts against the number of characters specified by the first argument. For example, if you want to truncate a string to exactly 10 characters, and use a 3-character ellipsis, use 13 for the first argument of truncate, since the ellipsis counts as 3 characters.
{{ "Ground control to Major Tom." | truncate: 25, ", and so on" }}
Ground control, and so on

No ellipsis

You can truncate to the exact number of characters specified by the first argument and avoid showing trailing characters by passing a blank string as the second argument:
{{ "Ground control to Major Tom." | truncate: 20, "" }}
Ground control to Ma

split

Divides a string into an array using the argument as a separator. split is commonly used to convert comma-separated items from a string to an array.
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}

{% for member in beatles %}
  {{ member }}
{% endfor %}
John

  Paul

  George

  Ringo

truncatewords

Shortens a string down to the number of words passed as an argument. If the specified number of words is less than the number of words in the string, an ellipsis (…) is appended to the string.
{{ "Ground control to Major Tom." | truncatewords: 3 }}
Ground control to...

Custom ellipsis

truncatewords takes an optional second argument that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (…), but you can specify a different sequence.
{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}
Ground control to--

No ellipsis

You can avoid showing trailing characters by passing a blank string as the second argument:
{{ "Ground control to Major Tom." | truncatewords: 3, "" }}
Ground control to

normalize_whitespace

Replace any occurrence of whitespace with a single space.
{{ "a \n b" | normalize_whitespace }}
a b

number_of_words

Count the number of words in some text. This filter takes an optional argument to control the handling of Chinese-Japanese-Korean (CJK) characters in the input string:
  • Passing 'cjk' as the argument will count every CJK character detected as one word irrespective of being separated by whitespace.
  • Passing 'auto' (auto-detect) works similar to 'cjk' but is more performant if the filter is used on a variable string that may or may not contain CJK chars.
{{ "Hello world!" | number_of_words }}
2
{{ "你好hello世界world" | number_of_words }}
1
{{ "你好hello世界world" | number_of_words: "cjk" }}
6
{{ "你好hello世界world" | number_of_words: "auto" }}
6

array_to_sentence_string

Convert an array into a sentence. Useful for listing tags. Optional argument for connector.
{{ "foo,bar,baz" | split: "," | array_to_sentence_string }}
foo, bar, and baz
{{ "foo,bar,baz" | split: "," | array_to_sentence_string: "or" }}
foo, bar, or baz