Home › Forums › ACF PRO › oEmbed params › Reply To: oEmbed params
Add this to functions.php file:
add_action( 'run_video_embed', 'video_embed' );
function video_embed( $context ) {
$video = get_field( 'media' );
if ( $video ) {
// Add autoplay functionality to the video code
if ( preg_match('/src="(.+?)"/', $video, $matches) ) {
// Video source URL
$src = $matches[1];
// Add option to hide controls, enable HD, and do autoplay -- depending on provider
$params = array(
'controls' => 1,
'hd' => 1,
'fs' => 1,
'rel' => 0,
'modestbranding' => 1,
'autoplay' => 0
);
$new_src = add_query_arg($params, $src);
$video = str_replace($src, $new_src, $video);
// add extra attributes to iframe html
$attributes = 'frameborder="0"';
$video = str_replace('></iframe>', ' ' . $attributes . '></iframe>', $video);
}
echo '<div class="video-embed">', $video, '</div>';
}
}
and add this in Twig
{% do action('run_video_embed') %}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.