1

I normally embed videos by directly writing the URL in the WP built in [embed] code. Like: [embed]https://www.youtube.com/watch?v=p_o4aY7xkXg[/embed]

But now I want this video to open automatically with Turkish subtitles regardless of the user's preferences. How to do that?

I have tried adding these to URL, but none of them worked:

  • &yt:cc=on
  • &hl=tr
  • &cc_lang_pref=tr
  • &cc_load_policy=1

For example for TED videos I achieve it by adding "/lang/tr/" in URL, like this:

[embed]https://www.ted.com/talks/lang/tr/ken_robinson_says_schools_kill_creativity.html[/embed]

Any similar solution for Youtube? Or any other suggestions?

Update: I put iframe code directly in "Text" section of Post editor. It works. Example:

<iframe src="https://www.youtube.com/embed/1a8pI65emDE?rel=0&cc_load_policy=1&hl=tr" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen"></iframe>

This doesn't work if you put it in Visual editor. A bit confusing for non-developers.

4
  • 1
    Do you know that Youtube itselfs offers that option for embeds? Because if not it doesn't really matter on the side of WordPress. If yes can you add links to he docs?
    – kraftner
    Commented Feb 25, 2016 at 12:55
  • Yes it does. But via iframe. I dont know any solution via direct URL
    – someka
    Commented Feb 25, 2016 at 18:40
  • Please post the example iframe that works so we can help to adapt WP to generate the embed like that.
    – kraftner
    Commented Feb 25, 2016 at 19:02
  • Added the example iframe code
    – someka
    Commented Feb 26, 2016 at 9:51

1 Answer 1

2

Okay the thing is that the oembed endpoint seems not to support any other than the default parameters.

So it seems that all you can do is parse the response and add in your parameters to the iframe src. This should do it (untested)

function wpse_218836_add_youtube_parameter( $return, $data, $url ){
    if ( $data->provider_name === 'YouTube'){
        $additional_parameters = '&cc_load_policy=1&hl=tr';
        return preg_replace('/src="(.*?)"/i', 'src="$1' . $additional_parameters . '"', $return);
    }else{
        return $return;
    }
}

add_filter('oembed_dataparse', 'wpse_218836_add_youtube_parameter', 10, 3);

Your Answer

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

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