3

I am trying to get some oembed parameters attached to my Vimeo clips. I tried to get it going using the following two instructions:

Unfortunately what works for YouTube won't work for Vimeo, as the returning URL has no such string as ?feature=oembed that I can make str_replace work on. It is just the video's id at the end of the URL, which is random. I can make it work if I enter the exact ID of the clip to make str_replace look for.

Any idea how to make the function look for numbers and attach the parameters? An example clip would be

http://vimeo.com/14956293

and the oEmbed should be

//player.vimeo.com/video/14956293?color=FFFFFF&title=0&byline=0. 

As you can see here, there is another difference to YouTube. The arguments start with? and connects the arguments with &. Whereas YouTube begins with & and also connects the arguments with &.

1 Answer 1

0

You should add a filter on oembed provider to allow customs parameters:

add_filter( 'oembed_fetch_url', 'my_oembed_fetch_url', 10, 3 );

function my_oembed_fetch_url( $provider, $url, $args ) {
    // You can find the list of defaults providers in WP_oEmbed::__construct()
    if ( strpos( $provider, 'vimeo.com' ) !== false) {
        // Check the full list of args here: https://developer.vimeo.com/apis/oembed
        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;
}

then, in your template:

<?php wp_oembed_get('http://vimeo.com/44633289', array('color' => '7AB800')); ?>

or via a shortcode in post's content:

[vimeo 44633289 color=7AB800]

and you can do the same for youtube and all others oembed providers (if your my_oembed_fetch_url allow it)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.