From 1129dcf586535923708055adc67c924685bcad5c Mon Sep 17 00:00:00 2001 From: Carlos Bravo <37012961+c4rl0sbr4v0@users.noreply.github.com> Date: Wed, 27 Dec 2023 15:25:50 +0100 Subject: [PATCH] Modules API: Fix Interactivity not working on Classic Themes. (#57396) * Move modules scripts to footer on classic themes * Move only required modules * Move also the module preloads * Make preload only for block themes at head * Revert "Make preload only for block themes at head" This reverts commit 3edb69fc6f2ef4ea38b5ce4e4fa97425a0de2b1d. --- .../modules/class-gutenberg-modules.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/experimental/modules/class-gutenberg-modules.php b/lib/experimental/modules/class-gutenberg-modules.php index bbe51f1376a7d..0a2da03545776 100644 --- a/lib/experimental/modules/class-gutenberg-modules.php +++ b/lib/experimental/modules/class-gutenberg-modules.php @@ -262,14 +262,15 @@ function gutenberg_dequeue_module( $module_identifier ) { Gutenberg_Modules::dequeue( $module_identifier ); } -// Prints the import map in the head tag. -add_action( 'wp_head', array( 'Gutenberg_Modules', 'print_import_map' ) ); +$modules_position = wp_is_block_theme() ? 'wp_head' : 'wp_footer'; +// Prints the import map in the head tag in block themes. Otherwise in the footer. +add_action( $modules_position, array( 'Gutenberg_Modules', 'print_import_map' ) ); -// Prints the enqueued modules in the head tag. -add_action( 'wp_head', array( 'Gutenberg_Modules', 'print_enqueued_modules' ) ); +// Prints the enqueued modules in the head tag in block themes. Otherwise in the footer. +add_action( $modules_position, array( 'Gutenberg_Modules', 'print_enqueued_modules' ) ); -// Prints the preloaded modules in the head tag. -add_action( 'wp_head', array( 'Gutenberg_Modules', 'print_module_preloads' ) ); +// Prints the preloaded modules in the head tag in block themes. Otherwise in the footer. +add_action( $modules_position, array( 'Gutenberg_Modules', 'print_module_preloads' ) ); // Prints the script that loads the import map polyfill in the footer. add_action( 'wp_footer', array( 'Gutenberg_Modules', 'print_import_map_polyfill' ), 11 );