Skip to content

Twitter embeds in wrong language

I realize when i try to publish a twit embed with WordPress, it was showing it in wrong language.. as german! Seems twitter is trying to decide language depending on your server’s location because my server is in Germany so twit embeds were in german language. Here is proper fix:

add_filter( 'oembed_fetch_url', 'firmasite_oembed_twitter_lang', 10, 3 );
function firmasite_oembed_twitter_lang( $provider, $url, $args ) {
	if ( 'twitter.com' == parse_url( $url, PHP_URL_HOST ) ) {
		$lang = explode("-", get_bloginfo('language'));
		$provider = add_query_arg( 'lang', urlencode( $lang[0] ), $provider );
	}
	return $provider;
}

8 thoughts on “Twitter embeds in wrong language

  1. Steve says:

    Hi,

    Super newbie here. I know this goes in fuctions.php but what text do I change to make it specific to my website in order to get english?

    Thanks!

    Reply
    • Avatar of Ünsal Korkmaz
      Ünsal Korkmaz says:

      You dont need to change anything. That code is looking to blog’s language and using it for twitter language. If you change your language, it will change twitter’s display language too :)

      Reply
  2. John, Bang Digital says:

    Thanks for the solution.

    This was a problem I had fixed for author twitter links but I still had a problem with embedded links within WordPress posts.

    WordPress seem to be ignoring this problem on their feedback boards so I hope they implement your fix in the next update.

    Reply
    • Avatar of Ünsal Korkmaz
      Ünsal Korkmaz says:

      I dont think they will implement this anytime soon because there is no “wordpress” way to get language code atm. We are splitting get_bloginfo('language') which is a php way rather then a wordpress way

      Reply
  3. Dave says:

    I added this code to my funtions.php and Ii still have Chinese characters showing up. Is there something else I need to do?

    Reply
    • Avatar of Ünsal Korkmaz
      Ünsal Korkmaz says:

      I cant tell what is wrong without see the problem. Is your site live?

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *