Home › Forums › General Issues › Youtube embed deffer loading › Reply To: Youtube embed deffer loading
Commenting to remind others like myself: don’t forget to set ‘jquery’ as the dependency when enqueueing John’s script. Otherwise, you might receive “Uncaught TypeError: url.indexOf is not a function”.
add_action( 'wp_enqueue_scripts', function() {
wp_enqueue_script('load-deferred-videos-js', get_template_directory_uri() . '/static/js/load-deferred-videos.js', ['jquery']);
});
Notice ['jquery']
as the third argument to wp_enqueue_script
.
P.S.
If you only want to load this script on a custom post type, such as “car”, then wrap the wp_enqueue_script
function inside an if-clause.
if (is_singular('car')) {
wp_enqueue_script('load-deferred-videos-js', get_template_directory_uri() . '/static/js/load-deferred-videos.js', ['jquery']);
}
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.