Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@EdenK
Last active March 14, 2024 13:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save EdenK/dc7b59eb1d26f7121c236ea1d06f3b3f to your computer and use it in GitHub Desktop.
Save EdenK/dc7b59eb1d26f7121c236ea1d06f3b3f to your computer and use it in GitHub Desktop.
Filter to add enablejsapi to Elementor youtube video
<?php
/**
* Filter to add enablejsapi to Elementor youtube video
*/
function add_youtube_jsapi($iframe_html, $video_url, $frame_attributes) {
if(strpos($video_url, 'youtube') !== false) {
$src = esc_attr($frame_attributes['src']);
$new_src = esc_attr(add_query_arg(array('enablejsapi' => '1'), $frame_attributes['src']));
$iframe_html = str_replace($src, $new_src, $iframe_html);
}
return $iframe_html;
}
add_filter( 'oembed_result', 'add_youtube_jsapi', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment