#23: wp_sprintf_l

The wp_sprintf_l filter allows you to modify the default list item separators used in lists employing the %l specifier — such as when using the the_taxonomies() template tag. When we say “separators”, we’re talking about the punctuation and/or punctuation + words used to grammatically space items in a list.

For example:

  • If there are two taxonomy terms, the separator would be ‘ and ‘, e.g. ‘Something and Something Else’
  • If there are three or more terms, the separator ‘, ‘ would be used up until the last term, then the separator used would be ‘, and ‘, e.g. ‘Something, Something Else, and Something Else Again’

It is evaluated in wp_sprintf_l() in the wp-includes/formatting.php file. wp_sprintf_l() exists to make these default item separators localizable for different languages.

Important note: You should exercise caution modifying the default separators as translators use them as a guide.

wp_sprintf_l accepts a single argument that takes the form of an array. Each key/value pair in the array specifies a different type of list item separator:

  • 'between' => ', '
  • 'between_last_two' => ', and '
  • 'between_only_two' => ' and '

Example:

Let’s say you’re one of those people who just can’t stand the serial/Oxford comma, the following will modify the between_last_two key in the wp_sprint_l separators array.

View the code example on Gist.