6

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

 2 years ago
source link: https://pineco.de/snippets/use-variables-inside-translation-functions-_e-__-in-wordpress/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK