0

I have a custom field where I define the Youtube Url as a string.

https://www.youtube.com/watch?v=3VqHtEF3LPE

This then becomes the src in my theme's shortcode:

<?php 
    $ysrc = get_field('fl_tube');
    if($ysrc) :
        $poster = wp_get_attachment_image_src( get_post_thumbnail_id( $entry_id ), 'entry-fullwidth', false ); 
        echo do_shortcode( '[x_video_player src="' . $ysrc . '" poster="' . $poster[0] . '" preload="metadata" hide_controls="false" autoplay="false" loop="false" muted="false" no_container="true"]' ); 
?>

Wordpress renders this code and produces:

<div class="mejs-mediaelement">
    <iframe class="me-plugin" id="me_youtube_0_container" frameborder="0" allowfullscreen="1" title="YouTube video player" width="480" height="270" src="https://www.youtube.com/embed/3VqHtEF3LPE?controls=0&amp;wmode=transparent&amp;enablejsapi=1&amp;origin=https%3A%2F%2Fwww.mydomain.com&amp;widgetid=1">
    </iframe>
</div>

In order to hide relative videos and info, I need to append to the url in iframe src:

&amp;rel=0&amp;showinfo=0

I cannot add this in my custom field string because then the iframe src output displays erroneously as:

src="https://www.youtube.com/embed/3VqHtEF3LPE?rel=0?controls=0&amp;wmode=transparent&amp;enablejsapi=1&amp;origin=https%3A%2F%2Fwww.mydomain.com&amp;widgetid=1"

Is there a workaround using javascript or a function maybe to append &amp;rel=0&amp;showinfo=0 to the iframe src for all youtube videos embedded on my site.

0

Try to wordpress function embed

<?php 
        global $wp_embed;
        echo $wp_embed->run_shortcode('[embed width="123" height="456"]http://www.youtube.com/watch?v=dQw4w9WgXcQ[/embed]'); 
?>
  • This embeds YouTube's embed object, not mediaelement video player. – brownian Dec 9 '17 at 14:04

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.