Changing the language mid-post on WordPress

You might come across a situation where you want to put a paragraph from a different language in the middle of your blog post. I was recently asked how to do just this, and unfortunately, there is no Gutenberg block for this.

I could make a plugin which does all of this for you, but I’m against installing too many plugins. For something so simple, you can simply do it manually.

To do this, you need to insert a “Custom HTML” block (found under “formatting” in Gutenberg) and put the following code snippet. The first line starts a paragraph, with the language attribute of “fr” for French. You can see what the ISO language code for your language is here. After that, you should put your paragraph text. Once you’re done, you need to close that paragraph with the </p> tag.

<p lang="fr">
<!== YOUR CONTENT HERE ==>
</p>

The benefit of this is that google and other search engines can easily identify the language. Furthermore, browsers may be able to offer translations to visitors.

For some right-to-left languages, such as Arabic, Urdu or Hebrew, you may find it useful to also specify a direction attribute:

<p lang="ur" dir="rtl">
<!== YOUR CONTENT HERE ==>
</p>

If this is something which you need to do often, you may find it useful to add one of the above examples to your reusable blocks so that you can simply change the content each time.

I hope that this might have been of some use to you! Good luck!

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.