Last active
March 14, 2024 13:37
-
-
Save EdenK/dc7b59eb1d26f7121c236ea1d06f3b3f to your computer and use it in GitHub Desktop.
Filter to add enablejsapi to Elementor youtube video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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