Last active
October 14, 2019 15:55
-
-
Save nickcernis/434a870494b3f1dc03ae5dd22f58131d to your computer and use it in GitHub Desktop.
Prevent 'NotAllowedError' and 'user didn't interact with the document first' errors for Vimeo embedded in WordPress. No longer needed in WP 5.3 beta 3 or higher.
This file contains hidden or 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
Add the code in the functions.php file below to your active theme's functions.php file. | |
You can remove the code once WordPress updates to media element 4.2.10+. (WordPress 5.3 beta 3 updated from 4.2.6 to 4.2.13: https://wordpress.org/news/2019/10/wordpress-5-3-beta-3/) |
This file contains hidden or 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
add_action( 'wp_enqueue_scripts', 'studiopress_load_newer_vimeo_mediaelement', 100 ); | |
/** | |
* Replace the mediaelement-vimeo script with a newer version. | |
* | |
* This works around an issue in WordPress core that can prevent playback of | |
* Vimeo videos embedded via the `wp_video_shortcode()` function. | |
* | |
* This is caused by WordPress loading an older version of the Vimeo script | |
* (currently loads 4.2.6), which does not add the 'allow=autoplay' | |
* attribute to iframes that Chrome now requires to permit video playback as | |
* the first user action on a page. | |
* | |
* See https://github.com/mediaelement/mediaelement/issues/2618. | |
* | |
* This code and the `add_action` line above could be removed once WordPress | |
* updates to use Media Element 4.2.10+. | |
*/ | |
function studiopress_load_newer_vimeo_mediaelement() { | |
wp_dequeue_script( 'mediaelement-vimeo' ); | |
wp_deregister_script( 'mediaelement-vimeo' ); | |
wp_enqueue_script( | |
'mediaelement-vimeo', | |
'https://cdn.jsdelivr.net/gh/mediaelement/[email protected]/src/js/renderers/vimeo.js', | |
array( 'mediaelement' ), | |
'4.2.10', | |
1 | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment