Skip to content

Instantly share code, notes, and snippets.

@kevinlisota
Created April 28, 2015 03:02
Show Gist options
  • Save kevinlisota/210651cf9e39093938ba to your computer and use it in GitHub Desktop.
Save kevinlisota/210651cf9e39093938ba to your computer and use it in GitHub Desktop.
Omit Twitter widgets.js script in HTML returned from oEmbed endpoint in WordPress
<?php
function omit_twitter_script($provider, $url, $args) {
//get the hostname of the oEmbed endpoint provider being called
$host = parse_url($provider, PHP_URL_HOST);
//check to see that hostname is twitter.com
if (strpos($host, 'twitter.com') !== false) {
//adding ?omit_script=true to oEmbed endpoint call stops the returned HTML from containing widgets.js
$provider = add_query_arg('omit_script', 'true', $provider);
}
//return the $provider URL so the oEmbed can be fetched
return $provider;
}
add_filter('oembed_fetch_url', 'omit_twitter_script', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment