Wordpress loading wrong language for Facebook SDK

2019-07-27 06:23发布

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&amp;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.

Here is an example post that comes up in Arabic on the website. This is also what we are inserting into Wordpress to create the embedded post.

https://www.facebook.com/farahdhukai/videos/1217650958285047/

Here is where it is appearing in Arabic instead of English

http://mvs.dev.clickharder.net/facebook-sdk-test/

The top embed is using the Wordpress embed feature by just adding the URL of the video. The bottom embed is using the Facebook iframe embed method for testing purposes.

I haven't figured out how to either disable the Facebook SDK within Wordpress so I can insert it myself 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 a 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.

1条回答
太酷不给撩
2楼-- · 2019-07-27 07:08

@CBroe provided the same solution I went with. I added the following code to replace the reference.

add_filter( 'the_content', 'facebook_sdk_replace' );
function facebook_sdk_replace( $content ) {
    if ( is_single() ) {
        $content = str_replace("/ar_AR/", "/en_US/", $content);
    }
    return $content;
}
查看更多
登录 后发表回答