Conditional Shortcode Based on Language

Conditional Shortcode Based on Language

Things like emails sent to users by different plugins cannot be translated using the visual translation interface because they do not appear in the front-end.
For these other types of content you can use the conditinal shortcode to display content based on language:
[trp_language language="en_US"] English content only [/trp_language]
This can be done also with PHP:

Another use case of the conditional shortcode is for translating images, basically displaying different images for different languages.
[trp_language language="en_US"]

[/trp_language]
[trp_language language="fr_FR"]

[/trp_language]

However, this can now be easily achieved directly from the front-end using the built in image translation functionality.
It is also possible to use the conditional shortcode to display Gutenberg blocks only on the desired language.
To do this, you will have to wrap the Gutenberg block between two shortcode blocks. The first shortcode block will contain the start of our conditional shortcode ([trp_language language=」en_US」]) and the second block will contain the end of our conditional shortcode ([/trp_language]).

The result can be seen in the following image. The first page is the default English version and the second page is the Spanish version of the same page.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注