Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

madwillsy commented Nov 28, 2017

You my friend are a legend!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.