Skip to main content
Share Your Experience: Take the 2024 Developer Survey
12 votes

How to manually link posts to each other in Wordpress

I'll use as example two pages: Hello (en) and Bonjour (fr). Click "Edit" in page Hello (doesn't really matter which one) At the right sidebar there will be the language of the current page (English) ...
Dinei's user avatar
  • 221
6 votes
Accepted

Get Polylang available languages on admin page of my plugin

According to Polylangs Function Reference, pll_the_languages Displays a language switcher. And most probably it uses some additional CSS/JS to work. If you want to get the list of languages and ...
Krzysiek Dróżdż's user avatar
5 votes
Accepted

How to develop a multilingual theme?

Daniel's answer was very similar, but applied to plugins rather than themes. For that reason I'll explain how I specifically did it for themes for anyone else who comes across this problem. Create a ...
Ollie's user avatar
  • 181
5 votes

Changing the language of a single page

The locale filter that allows you to set the locale specifically. You can check the current page, and alter the value based on that. add_filter('locale', 'change_my_locale'); function ...
Johansson's user avatar
  • 15.3k
5 votes
Accepted

Make a custom theme translate-ready

To do it properly, you need to generate a valid .mo file and load the text domain in your theme functions.php: function wpse222346_localize_theme() { load_theme_textdomain( 'your_theme_domain', ...
Luis Sanz's user avatar
  • 756
4 votes

Multisite use language code as subdirectory

Here's a proper multisite solution: Install WordPress directly on the root of your domain mysite.de. After that, setup a multisite and chose the subdomain option (Yes, subdomain! It's far more ...
David's user avatar
  • 3,275
4 votes

Changing the language of a single page

You should use locale hook to solve your task. Important note that you can't add it in theme and use is_page function, because it will define later. So you have to create plugin or must use plugin ...
Anton Lukin's user avatar
4 votes

Get the ID of the default language equivalent page in Polylang

you can retrieve this identifier with that code : $defaultLanguage = pll_default_language(); $translations = pll_get_post_translations($post_ID); $id = $translations[$defaultLanguage];
mmm's user avatar
  • 3,704
4 votes

Get Polylang available languages on admin page of my plugin

You can get an array with the language details using the following call: if (function_exists('pll_languages_list')) { return pll_languages_list(array('fields' => array())); } The result is an ...
MuturiAlex's user avatar
3 votes
Accepted

Set language per post

I couldn't find an answer so I ended up providing the solution. It wasn't simple given that I am not an expert with wordpress nor with php but Wordpress documentation is great so here is the ...
Fahad Alduraibi's user avatar
3 votes

How to get a translated string from a language other than the current one?

To find the answer to this question, you just need to look at how WordPress retrieves the translations. Ultimately it is the load_textdomain() function that does this. When we take a look at its ...
J.D.'s user avatar
  • 3,915
3 votes

Get the ID of the default language equivalent page in Polylang

$post_id = pll_get_post( get_the_ID(), pll_default_language() ); Got this from the plugin author, works great!
website walrus's user avatar
3 votes

How to make WP in two languages (e.g. English & Bengali) without plugins

A way my agency has chosen to implement it in the past is through subdomains. We created the entirety of our English site as you would normally in WordPress on mydomain.com, used the Duplicator plugin ...
YourManDan's user avatar
2 votes

How to let users change site language?

Add filter in your child theme like this add_filter( 'locale', 'set_my_locale' ); function set_my_locale( $lang ) { if ( 'gl' == $_GET['language'] ) { // set to Greenlandic return 'ka_GL'; ...
Bilal Ahmed's user avatar
2 votes

detect the language a post is written in

For the rest api, wp-graphql and wp-cli's wp eval-file I needed to do wp_get_post_terms( $post->ID, 'language' )[0]->slug
esamatti's user avatar
  • 121
2 votes

Force Plugin to English Translation

// to force use English, this filter value must return true. add_filter('override_load_textdomain', 'myPlugin_OverrideLoadTextDomain', 10, 3); add_filter('plugin_locale', '...
vee's user avatar
  • 231
2 votes
Accepted

How to find a language direction?

The text_direction property of the WP_Locale class defaults to 'ltr' as per it's declaration, then may be modified in the class's init() initialization function in wp-includes/locale.php (near line #...
bosco's user avatar
  • 6,815
2 votes

How to use Internationalized human_time_diff() function in Chinese?

If you check out the source of human_time_diff: if ( $diff < HOUR_IN_SECONDS ) { $mins = round( $diff / MINUTE_IN_SECONDS ); if ( $mins <= 1 ) $mins = 1; /* translators: min=...
TheDeadMedic's user avatar
  • 36.4k
2 votes

Wordpress multilingual site using page-id.php files

I have developed pages in that manner and if you are using WordPress functions and follow WP Codex it is same situation as if you developed custom page template. Just follow I18n for WordPress ...
Vuk Vukovic's user avatar
2 votes
Accepted

How to use rewrite rule or rewrite endpoint to switch languages?

You cannot do this by just adding a rewrite rule, you need to change every recorded rules. Here is a simple way to do this: function my_rewrite_rules($rules) { $new_rules = array(); $...
maxime schoeni's user avatar
2 votes

How to develop a multilingual theme?

Myself I have done it a few times in recent year but then only for plug-ins that I made. But I think it will work sort or less the same. You indeed need to use the __() or similar function but also ...
Daniel Mulder's user avatar
2 votes

'Trick' a plugin (WP-Members) to think the blog language has changed for a single page

Yes, sort of. Any localized plugin such as WP-Members runs off of the "locale" that WordPress is set to. This value can be filtered for WP as a whole using the locale filter. But it can also be ...
butlerblog's user avatar
  • 4,996
2 votes
Accepted

Language Translation is not working?

Check the following function in your plugin: load_plugin_textdomain (); and be sure that the directory to languages folder is correct. This fixed the issue for above question.
HOY's user avatar
  • 291
2 votes

Changing the language of a single page

I needed something similar for translation & direction purposes. By defining $direction for each post, 'ltr' or 'rtl'...using this simple plugin ... I edited the plugin by adding following action ...
Kenan Hodzic's user avatar
2 votes

Translation plugin to translate another plugins

There are many translation plugins. I'd say check out Loco Translate: https://en-ca.wordpress.org/plugins/loco-translate/ Features include: Built-in translation editor within WordPress admin Create ...
Liam Stewart's user avatar
2 votes
Accepted

Create sub-domain for multisite and multi languages?

There are two ways to setup a multisite network, using subdomains and using subdirectories. Your current setup is for subdirectories and to change the URLs the way you want them you‘ll need to change ...
Carlos Rodríguez's user avatar
2 votes

Get Polylang available languages on admin page of my plugin

Polylang offers the function pll_languages_list() but note this will return only one type of value slug. You can use get_terms to query all languages with the name and slug included. get_terms( '...
Libla's user avatar
  • 21
2 votes
Accepted

Can anybody provide me with a function to generate slugs?

This post provides a function, but it cannot handle non-latin characters. That's because URLs can't have non-latin/ASCII characters. Browsers might show non-latin characters to you, but it's just a ...
Tom J Nowell's user avatar
  • 59.4k
2 votes

I display messages using code snippets but how can I use the right language?

You already have it in the code: __( 'Your message will only be visible after manual moderation', 'your_text_domain' ) __ is a translation function and part of the static string translation system in ...
Tom J Nowell's user avatar
  • 59.4k
2 votes
Accepted

How to get locale within WP REST Request?

There's only 2 real places a locale is defined in a vanilla WordPress install: For the site. For the user account. In the admin the user account's locale will be used, while on the front end the ...
Jacob Peattie's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible