Skip to content

Instantly share code, notes, and snippets.

@tomjn
Forked from jmdodd/gist:4055427
Created Nov 26, 2012
Embed
What would you like to do?
Set Twitter language for WordPress oEmbeds
global $wp_version;
if ( version_compare( $wp_version, '3.5', 'ge' ) ) {
if ( !function_exists( 'ucc_oembed_twitter_lang' ) ) {
function ucc_oembed_twitter_lang( $provider, $url, $args ) {
if ( stripos( $url, 'twitter.com' ) ) {
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 );
} else {
// The above filter was introduced in v3.5, for 3.4 replace the existing OEmbed line with a new one
add_filter('oembed_providers','twitter_oembed');
function twitter_oembed($a) {
if ( defined( 'WPLANG' ) )
$lang = strtolower( WPLANG );
if ( empty( $lang ) )
$lang = 'en';
$a['#https?://(www\.)?twitter.com/.+?/status(es)?/.*#i'] = array( 'http://api.twitter.com/1/statuses/oembed.{format}?lang='.$lang, true );
return $a;
}
}
/*
Copyright 2012 Jennifer M. Dodd (email: jmdodd@gmail.com)
Heavily Modified by Tom J Nowell ( contact@tomjn.com )
Released under the GPLv2 (or later).
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment