Hi Morten,
Thanks so much for upgrading!
There is a way we can filter the embed URL and add that parameter. The only catch is that this will make all of the Youtube Featured Videos autoplay. That said, I’ll see if I can add this as a selectable option in the next update.
Please add the following code to your child theme’s functions.php file:
<?php
remove_filter('oembed_result','ct_tracks_add_youtube_parameters', 10, 3);
function ct_tracks_child_add_youtube_parameters($html, $url, $args) {
// access post object
global $post;
// get featured video
if( ! empty( $post ) ) $featured_video = get_post_meta( $post->ID, 'ct_tracks_video_key', true );
// only run filter if there is a featured video
if( ! empty( $featured_video ) ) {
// only run filter on the featured video
if( $url == $featured_video ) {
// only add parameters if featured vid is a youtube vid
if( strpos($featured_video, 'youtube.com' ) || strpos($featured_video, 'youtu.be' ) ) {
// get user Youtube parameter settings
// flip their value so 1 means, yes HIDE it, NOT yes SHOW it.
$youtube_title = get_post_meta( $post->ID, 'ct_tracks_video_youtube_title', true ) ? 0 : 1;
$youtube_related = get_post_meta( $post->ID, 'ct_tracks_video_youtube_related', true ) ? 0 : 1;
$youtube_logo = get_post_meta( $post->ID, 'ct_tracks_video_youtube_logo', true ) ? 0 : 1;
$youtube_captions = get_post_meta( $post->ID, 'ct_tracks_video_youtube_captions', true );
$youtube_parameters = array(
'showinfo' => $youtube_title,
'rel' => $youtube_related,
'modestbranding' => $youtube_logo,
'cc_load_policy' => $youtube_captions,
'autoplay' => '1'
);
if ( is_array( $args ) ) {
$args = array_merge( $args, $youtube_parameters );
} else {
$args = $youtube_parameters;
}
$parameters = http_build_query( $args );
// Modify video parameters
$html = str_replace( '?feature=oembed', '?feature=oembed&' . $parameters, $html );
}
}
}
return $html;
}
add_filter('oembed_result','ct_tracks_child_add_youtube_parameters', 20, 3);
Once added, the videos should autoplay.