Created
October 9, 2013 06:04
-
-
Save remcotolsma/6896886 to your computer and use it in GitHub Desktop.
WordPress add 'id' attribute to Vimeo oEmbed HTML.
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 | |
/** | |
* Add 'id' attribute to Vimeo oEmbed HTML | |
*/ | |
function prefix_embed_oembed_html( $html, $url, $attr, $post_ID ) { | |
$fix = true; | |
$fix &= strpos( $html, 'vimeo.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
You my friend are a legend!