Skip to content

Instantly share code, notes, and snippets.

@eliorivero
Created November 5, 2012 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliorivero/4015177 to your computer and use it in GitHub Desktop.
Save eliorivero/4015177 to your computer and use it in GitHub Desktop.
Remove fixed width from embedded tweets in WordPress for responsiveness
/**
* 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