Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Created October 9, 2013 06:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remcotolsma/6896886 to your computer and use it in GitHub Desktop.
Save remcotolsma/6896886 to your computer and use it in GitHub Desktop.
WordPress add 'id' attribute to Vimeo oEmbed HTML.
<?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 );
@madwillsy
Copy link

You my friend are a legend!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment