Created
November 5, 2012 03:37
-
-
Save eliorivero/4015177 to your computer and use it in GitHub Desktop.
Remove fixed width from embedded tweets in WordPress for responsiveness
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
/** | |
* Remove fixed width from embedded tweets. First step to make them responsive. | |
* @param string $html HTML that should be used to embed | |
* @param string $url The URL to the content that should be attempted to be embedded. | |
* @param array $args Optional arguments. | |
* @author Elio Rivero | |
* @link http://www.ilovecolors.com.ar/ | |
*/ | |
function themesrobot_oembed_result($html, $url, $args){ | |
// Check if it's a tweet looking for 'twitter' in the url pasted in the post | |
if( stripos($url, 'twitter') ) { | |
// Before the tweet is processed, it's displayed as a blockquote | |
// with its width attribute set, so let's remove it. | |
return str_replace('width="500"', '', $html); | |
} | |
// Otherwise return the HTML as is. | |
return $html; | |
} | |
// Filter the result of the oEmbed extraction. | |
add_filter('oembed_result', 'themesrobot_oembed_result', 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment