Skip to content

Instantly share code, notes, and snippets.

@vishalbasnet23
Created March 16, 2015 08:33
Show Gist options
  • Save vishalbasnet23/8f6aa430106e4b0cd179 to your computer and use it in GitHub Desktop.
Save vishalbasnet23/8f6aa430106e4b0cd179 to your computer and use it in GitHub Desktop.
Adding Custom attributes to Oembed WordPress
<?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