Created
April 28, 2015 03:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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