Support » Fixing WordPress » Wrong language appearing in Facebook Embeds

  • We are trying to embed Facebook posts into WordPress using the URL of the post. This works fine except for the language is wrong. Instead of the language appearing in English, it is appearing in Arabic.

    I believe I have traced the problem to the Facebook SDK that is loaded by WordPress.

    This is the code that Facebook says to add to the page

    <div id="fb-root"></div>
    <script>(function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) return;
      js = d.createElement(s); js.id = id;
      js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>

    This is what WordPress is loading

    <div id="fb-root"></div>
    <p><script>(function(d, s, id) {  
        var js, fjs = d.getElementsByTagName(s) [0];
        if (d.getElementById(id)) return;
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/ar_AR/sdk.js#xfbml=1&version=v2.3";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>

    I believe that the issue is the “ar_AR” in the Facebook connection url instead of “en_US”. However, I cannot figure out how or where that is controlled.

    I checked the language selection in WordPress and English is selected. I tried a fresh WordPress 4.7 installation with no plugins and the problem still persists.

    I have tried adding the facebook post url directly in WordPress and using the embed shortcode and they both display in the wrong language. However, if I embed the iframe from Facebook into the post, it does display in English (but that didn’t surprise me.)

    I haven’t figured out how to either disable the Facebook SDK within WordPress so I can insert the code above or how to change it from ar_AR to en_US.

    I have searched through every reference to “Facebook” in a fresh WordPress install and have come up empty handed. I can’t find any references for “ar_AR” within WordPress that relates to this issue.

    We are trying to avoid using the iframe method of embedding posts. It is not ideal for our situation so that is not a solution for us.

    Any help is much appreciated.

Viewing 7 replies - 1 through 7 (of 7 total)
  • That’s interesting.

    Are you sure it is facebook? My guess is that a theme is overriding it or may be a SEO plugin?

    I don’t know if it is Facebook or WordPress. My guess is it is coming from the API response from Facebook, but I have no way of knowing.

    I thought it may be a plugin on our live site that was causing the issue. To test for this I created a fresh installation of WordPress 4.7 with no plugins using the 2017 theme. The same thing occurs, the language defaults to Arabic.

    That led me to believe that maybe it was the original language of the Facebook post. However, I found other embedded Facebook posts that are defaulting to Arabic including a post about a Ford F-150 out of Arkansas. That debunked the “original language” theory.

    The only thing that is the same in all the Arabic posts is the “ar_AR” instead of “en_US”. Really a bizarre problem.

    Alright, does this happen if you post the link directly or are you using some kind of sharing plugin?

    It happens if I post the link directly into the content box on the page. It happens if I use the embed shortcode on the page. It does NOT happen if I embed the iframe onto the page.

    We are using NO plugins. To troubleshoot this problem we setup a clean installation of WordPress with both the default plugins removed and we are using the 2017 theme. We are running WordPress 4.7.1 and 2017 Theme 1.1 as of this writing.

    Here is a link to the test. I have included above each test exactly what is entered into the content area.
    http://mvs.dev.clickharder.net/facebook-sdk-test/

    Thanks for your help.

    I have had the same problem, except with the language being Dutch.

    I then found it only happened when I embedded a link on a site hosted on the servers I use in Amsterdam.

    Exactly the same site cloned to a server in the UK and the language was English.

    The fix suggested at https://stackoverflow.com/questions/41550989/wordpress-loading-wrong-language-for-facebook-sdk works…

    
    add_filter( 'the_content', 'facebook_sdk_replace' );
    function facebook_sdk_replace( $content ) {
        if ( is_single() ) {
            $content = str_replace("/nl_NL/", "/en_US/", $content);
        }
        return $content;
    }
    

    @deargeek
    Any other suggestions if that snippet doesn’t help? I lost hope trying to fix this issue for over a month now

    Found the reason why this is happening, here.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Wrong language appearing in Facebook Embeds’ is closed to new replies.