public
Last active

Set Twitter language for WordPress oEmbeds

  • Download Gist
gistfile1.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
if ( !function_exists( 'ucc_oembed_twitter_lang' ) ) {
function ucc_oembed_twitter_lang( $provider, $url, $args ) {
if ( 'twitter.com' == parse_url( $url, PHP_URL_HOST ) ) {
if ( defined( 'WPLANG' ) )
$lang = strtolower( WPLANG );
if ( empty( $lang ) )
$lang = 'en';
 
$args['lang'] = $lang;
$provider = add_query_arg( 'lang', urlencode( $lang ), $provider );
}
return $provider;
} }
add_filter( 'oembed_fetch_url', 'ucc_oembed_twitter_lang', 10, 3 );
 
/*
Copyright 2012 Jennifer M. Dodd (email: jmdodd@gmail.com)
Released under the GPLv2 (or later).
*/

Here 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;
}

Details: http://unsalkorkmaz.com/twitter-embeds-in-wrong-language/

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.