Last active
December 14, 2016 10:31
-
-
Save alokstha1/c23c0fc997dbe6cd98a7e413f5a7240f to your computer and use it in GitHub Desktop.
Embed Vimeo video customization
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 | |
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 ); | |
} | |
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 ); | |
AND in template add | |
$oembed = wp_oembed_get( $vimeo_url, array( 'autoplay' => true, 'portrait' => 0, 'title' => 0, 'byline' => 0 ) ); | |
$oembed = str_replace('autoplay=1', 'autoplay=1&loop=1&background=1', $oembed); | |
echo $oembed; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment