Skip to content

Instantly share code, notes, and snippets.

@yurivictor
Last active January 3, 2016 09:39
Show Gist options
  • Save yurivictor/8444326 to your computer and use it in GitHub Desktop.
Save yurivictor/8444326 to your computer and use it in GitHub Desktop.
Fix for twitter oembeds in WordPress
<?php
/**
* Plugin Name: Fix Twitter Oembed
*/
class FixTwitterOembed {
private static $twitter_oembed_regex = '#https?://(www\.)?twitter\.com/.+?/status(es)?/.*#i';
public static function init() {
self::add_actions();
}
public static function add_actions() {
add_filter( 'oembed_providers', array( __CLASS__, 'fix_twitter_oembed' ) );
}
public static function fix_twitter_oembed( $providers ) {
if ( isset( $providers[self::$twitter_oembed_regex] ) ) {
$providers[self::$twitter_oembed_regex][0] = 'https://api.twitter.com/1/statuses/oembed.{format}';
}
return $providers;
}
}
FixTwitterOembed::init();
@jeremyescott
Copy link

I installed this and I didn't notice it work. Should this fix a 3.8 with just this plugin?

@jeffhester
Copy link

I've got the same issue. Installed and activated on 3.8, but Twitter oEmbeds are still not working.

@jeffhester
Copy link

Correction. It is working, but only after editing and re-saving a post. Weird?

@matthieumarechal
Copy link

It is working for me too ! Very efficient ! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment