0

I have multisite enabled in WordPress network to build multi language blog and using the following code to list all blogs within my network.

<?php $blog_list = get_blog_list(0, 'all'); foreach ($blog_list as $blog) {
  switch_to_blog( $blog['blog_id'] );
  $url = get_option( 'siteurl' );
  $name = get_option( 'blogname' );
  echo $name . ':'. $url .'<br />';
  restore_current_blog();
} ?>

Is there a way to get the language used on the blog from the code above?

2
  • 1
    Have you tried get_locale()?
    – birgire
    Jul 12, 2022 at 18:56
  • get_locale() only get the lang attribute of the current blog we visit. What I'm trying to do is to get the language of each blog in my network site.
    – Biyans
    Jul 20, 2022 at 17:18

1 Answer 1

0

A little bit late, but I just had the same problem.

Instead of get_locale() (which does not return the updated value after switch_to_blog()), you can use get_option( 'WPLANG' ).

// ...
switch_to_blog( $otherBlogId );
$language = get_option( 'WPLANG' );

// do something with $language

restore_current_blog()
// ...

In my case, get_option( 'WPLANG' ) returned an empty string when the language setting was set to "English/US". Something like the following worked:

$l = get_option( 'WPLANG' );
if ( empty( $l ) ) {
    $l = 'en_US';
}

Read more here:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.