Use Variables Inside Translation Functions (_e() __()) In WordPress

WordPressPosted on

To translate our plugins or themes in WordPress, we have many handy helper functions that we can use to pass through text and then later translate it.

But what if we want to pass dynamic data inside our static translatable string? In this case, we can combine the translate functions with the PHP’s sprintf like so:

echo sprintf(__('The validator of this post is: %s.', 'pine' ), $verifier_name);

Using sprintf we can insert variables inside strings. A particular character combination (%s) must always be present (in the translations, too); this special character will be replaced with the variable’s value.

Need a web developer? Maybe we can help, get in touch!

Similar Posts

More content in WordPress category