Created
March 16, 2015 08:33
-
-
Save vishalbasnet23/8f6aa430106e4b0cd179 to your computer and use it in GitHub Desktop.
Adding Custom attributes to Oembed WordPress
This file contains hidden or 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 | |
/** | |
* Add 'id' attribute to Vimeo oEmbed HTML | |
*/ | |
function prefix_embed_oembed_html( $html, $url, $attr, $post_ID ) { | |
$fix = true; | |
$fix &= strpos( $html, 'youtube.com' ) !== false; // Embed code from Vimeo | |
$fix &= strpos( $html, ' id=' ) === false; // No ID attribute supplied by Vimeo | |
$fix &= isset( $attr['player_id'] ); // Player ID supplied | |
if ( $fix ) { | |
$html = str_replace( | |
'<iframe ', | |
sprintf( '<iframe id="%s" ', esc_attr( $attr['player_id'] ) ), | |
$html | |
); | |
} | |
return $html; | |
} | |
add_filter( 'embed_oembed_html', 'prefix_embed_oembed_html', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment