Last active
April 18, 2020 23:30
-
-
Save benhuson/9f433b7af41a26ef6692 to your computer and use it in GitHub Desktop.
Customise WordPress Vimeo oEmbed
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 | |
/** | |
* Customise WordPress Vimeo oEmbed | |
* https://developer.vimeo.com/apis/oembed | |
*/ | |
function my_oembed_fetch_url( $provider, $url, $args ) { | |
if ( strpos( $provider, 'vimeo.com' ) !== false) { | |
if ( isset( $args['autoplay'] ) ) { | |
$provider = add_query_arg( 'autoplay', absint( $args['autoplay'] ), $provider ); | |
$provider = add_query_arg( 'muted', '1', $provider ); | |
} | |
if ( isset( $args['color'] ) && preg_match( '/^[a-f0-9]{6}$/i', $args['color'] ) ) { | |
$provider = add_query_arg( 'color', $args['color'], $provider ); | |
} | |
if ( isset( $args['portrait'] ) ) { | |
$provider = add_query_arg( 'portrait', absint( $args['portrait'] ), $provider ); | |
} | |
if ( isset( $args['title'] ) ) { | |
$provider = add_query_arg( 'title', absint( $args['title'] ), $provider ); | |
} | |
if ( isset( $args['byline'] ) ) { | |
$provider = add_query_arg( 'byline', absint( $args['byline'] ), $provider ); | |
} | |
} | |
return $provider; | |
} | |
add_filter( 'oembed_fetch_url', 'my_oembed_fetch_url', 10, 3 ); | |
echo wp_oembed_get( 'http://vimeo.com/105300667', array( 'autoplay' => true, 'color' => 'ffffff', 'portrait' => 0, 'title' => 0, 'byline' => 0 ) ); | |
?> |
Autoplay now requires the video to be muted to work.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @benhuson Nice code here! I'm having trouble getting this gist to output an iframe. Have there been any changes perhaps?