In this tutorial, we will show you how to write a wordpress post in a different language (which is not the main language of your wordpress website).
In order to avoid any confusion, let's clarify a little : we won't talk about how to translate a post into several languages (there are lots of tutorials for that, most of which use the Polylang plugin).
We simply want to set a language per post. For example, on this website (modeseeker.com), some posts are in English like this one, but most are in French.
Why is it interesting ?
Specifying a language per post has several advantages :
- Search engines will understand that your post is written in the specified language,
- The post data (such as date, number of comments, etc.) and navigation buttons will be displayed in the correct language,
- You will then be able to use the post language to trigger different behaviours on your website depending on the language. (for example banners, ads, etc.).
How to do it
It's very simple : just install the "Per Post Language" plugin by Fahad Alduraibi. It isn't in the official WordPress plugin directory anymore, but you can find it here :
https://modeseeker.com/wp-content/uploads/2021/01/per-post-language.1.3.zip
You will have to install it manually : go to Plugins, then Add Plugins, and Upload Plugin.
Upload the zip file and click install. Then go to Per Post Language settings, and add the languages you need to the "selected languages" list.
Then, edit the post for which you want to set a different language. On the right panel, you should see a list of the available languages. Select the one you want, and you're done !
If you want to check the language specified to search engines, check the source code of your page. You should see it on the second line of the source code :
Finally, if you need to trigger different behaviours on your webiste based on a post language, you can use the following syntax in your wordpress structure files :
if(strstr(get_bloginfo("language"),"fr-FR")==true)
{
?>
<div>Your text here</div>
<?php
}
In this example, we check whether the post is in French to display a div containing text.
That's it ! Thanks to this great WordPress plugin, you can now write posts in multiple languages, knowing that the user experience of your visitors will be perfect and that you will be correctly indexed by search engines.
If you have any question, don't hesitate to leave us a reply below, we reply within 24h.
Hi,
And how will your plug-in work when the contents in different languages from external sites are presented on the news site based on permission to share them?
Thank you.
Good luck.
Zbigniew