0

I'm trying to add some parameters to oEmbeded Vimeo videos on my homepage template. I used the solution (with add_query_arg) that @splashingpixels suggested here: Add parameters vimeo videos using wordpress embeds

add_query_arg adds the parameters to the URL ok, and var_dump is printing the URL text to the page confirming that the parameters are being added.

The embedded video below the var_dump is not getting the parameter'd URL, only the normal Vimeo URL.

I'm not getting any errors from WP_DEBUG.

This is the testing site: http://thegallerymusic.com/test/

This is my loop code:

<?php $args = array( 'post_type' => 'films', 'posts_per_page' => 12 );
          $the_query = new WP_Query( $args ); ?>

    <?php if ( $the_query->have_posts() ) : ?>
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

            <?php /* Get the current post ID. */
                    global $post;
                    $post_id = $post->ID;
                  /* If we have a post ID, proceed. */
                    if ( !empty( $post_id ) ) { ?>

                    <div class="film_wrap col-md-4">

                        <?php // <h2 class="film_title"><?php the_title(); ?><?php //</h2> ?>

                        <?php $videourl = get_post_meta( $post_id, 'film_embed', true );
                              $videourl = add_query_arg( 
                                array('title'    => '0',
                                      'byline'   => '0',
                                      'portrait' => '0',
                                      'badge'    => '0',), $videourl );
                                var_dump($videourl);

                              if ( $videourl != '' ) {
                                echo wp_oembed_get( $videourl ); 
                              } ?>

                        <?php if ( get_post_meta( $post_id, 'film_textarea', true ) ) : ?>
                            <div class="film_description">
                                <p><?php echo get_post_meta( $post_id, 'film_textarea', true ); ?></p>
                            </div>
                        <?php endif; ?>

                    </div>

                        <?php wp_reset_postdata(); ?>

                    <?php } else { ?>

                        <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>

                    <?php } ?>

        <?php wp_link_pages( array(
            'before' => '<div class="page-links">' . __( 'Pages:', '_tk' ),
            'after'  => '</div>',
        ) ); ?>

    <?php endwhile; ?>
    <?php endif; ?>
3

Take out the var_dump. That is debugging code, it's dumping the variable so that you can see what it is.

Edit: Okay, I think you're asking the wrong question here, as did the other person in the question that you linked to.

Adding additional query args onto the URL being sent to wp_ombed_url() won't cause the oembed system to send them on to the oembed provider endpoint. You need to add them as arguments to the provider, not as arguments to the URL that you're requesting to be embedded.

You would need to use a filter to add the parameters to the actual oembed request, not to the URL parameter. Like so:

add_filter('oembed_fetch_url','example_add_vimeo_args',10,3);
function example_add_vimeo_args($provider, $url, $args) {
    if ( strpos($provider, '//vimeo.com/') !== false ) {
        $args = array(
            'title' => 0,
            'byline' => 0,
            'portrait' => 0,
            'badge' => 0
        );
        $provider = add_query_arg( $args, $provider );
    }
    return $provider;   
}

See, the URL is the URL of the video that you want to be embedded. WordPress contacts that provider's oembed endpoint to get the embed code for that video. If you want to change the response from that endpoint, then you have to change the arguments to the endpoint, not the arguments to the URL it's asking about.

  • Sorry, I got that. I updated my question to specify that var_dump is showing the correct URL, but that URL isn't being inserted into the oEmbed output HTML. Any ideas? – dmoz Sep 8 '14 at 19:53
  • Edited my answer. – Otto Sep 8 '14 at 20:16
  • Ok, that's definitely the answer. It added the parameters to the correct URL, the one used by the embed HTML. I'm learning now, though, since that didn't actually remove the title, byline, portrait, badge, etc, that any of those video controls have to be changed via the Vimeo backend. Parameters on the URL of an embedded Vimeo video won't change that stuff :\ Hope this helps anyone else struggling with this same thing. – dmoz Sep 8 '14 at 20:27
  • In Vimeo's docs, it states this: developer.vimeo.com/apis/oembed "If the owner of a video is a Plus or PRO member, some of these settings may be overridden by their preferences." – Otto Sep 8 '14 at 20:36
  • Yea, I think that's why the appended parameters aren't taking. Thanks again for your help! Very helpful if I end up needing them. – dmoz Sep 8 '14 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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