From 539720f7f04c998c05f79ad2fa3285d379b97315 Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Wed, 4 Sep 2024 11:13:09 +1200 Subject: [PATCH] Theme: Dequeue Sensei course archive JS Not required and allows jQuery loading to be deferred. Fixes https://github.com/WordPress/Learn/issues/2679 --- .../themes/pub/wporg-learn-2024/functions.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/wp-content/themes/pub/wporg-learn-2024/functions.php b/wp-content/themes/pub/wporg-learn-2024/functions.php index 94bc8180e..52157306e 100644 --- a/wp-content/themes/pub/wporg-learn-2024/functions.php +++ b/wp-content/themes/pub/wporg-learn-2024/functions.php @@ -38,6 +38,7 @@ add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\maybe_enqueue_sensei_assets', 100 ); // Attached at 11 to run after scripts are registered, but before they are enqueued. add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\defer_scripts', 11 ); +add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\remove_sensei_course_archive_js', 100 ); // Remove Jetpack CSS on frontend add_filter( 'jetpack_implode_frontend_css', '__return_false', 99 ); @@ -251,6 +252,19 @@ function defer_scripts() { } } +/** + * Remove Sensei course archive JavaScript for performance. + * Not needed as we don't display Sensei course order controls. + */ +function remove_sensei_course_archive_js() { + if ( is_admin() || ! is_post_type_archive( 'course' ) ) { + return; + } + + wp_dequeue_script( 'sensei-course-archive-js' ); + wp_deregister_script( 'sensei-course-archive-js' ); +} + /** * Dequeue Sensei video scripts loaded on lessons archive. * Sensei LMS and Sensei Pro both enqueue video player scripts for lesson posts,