{"id":5816,"date":"2026-02-12T20:45:29","date_gmt":"2026-02-13T01:45:29","guid":{"rendered":"https:\/\/chubes.net\/?documentation=script-modules-functions"},"modified":"2026-03-13T03:29:22","modified_gmt":"2026-03-13T07:29:22","slug":"script-modules-functions","status":"publish","type":"documentation","link":"https:\/\/chubes.net\/docs\/wordpress-core\/script-modules\/script-modules-functions\/","title":{"rendered":"Script Modules Functions"},"content":{"rendered":"<p>Global functions for registering and managing script modules.<\/p><p><strong>Source:<\/strong> <code>wp-includes\/script-modules.php<\/code><\/p><hr class=\"wp-block-separator\"\/><h2 class=\"wp-block-heading\">wp_script_modules()<\/h2><p>Retrieves the main <code>WP_Script_Modules<\/code> instance.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">function wp_script_modules(): WP_Script_Modules<\/code><\/pre><\/div><p><strong>Since:<\/strong> 6.5.0<\/p><h3 class=\"wp-block-heading\">Description<\/h3><p>Provides access to the singleton <code>WP_Script_Modules<\/code> instance, creating one if it doesn&#8217;t exist yet. This is the central registry for all script modules.<\/p><h3 class=\"wp-block-heading\">Return<\/h3><p><code>WP_Script_Modules<\/code> \u2014 The main script modules instance.<\/p><h3 class=\"wp-block-heading\">Example<\/h3><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Access the registry directly\n$registry = wp_script_modules();\n$queue = $registry-&gt;get_queue();<\/code><\/pre><\/div><hr class=\"wp-block-separator\"\/><h2 class=\"wp-block-heading\">wp_register_script_module()<\/h2><p>Registers the script module if no script module with that identifier has already been registered.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">function wp_register_script_module(\n    string $id,\n    string $src,\n    array $deps = array(),\n    $version = false,\n    array $args = array()\n)<\/code><\/pre><\/div><p><strong>Since:<\/strong> 6.5.0<br \/>\n<strong>Updated:<\/strong> 6.9.0 \u2014 Added the <code>$args<\/code> parameter.<\/p><h3 class=\"wp-block-heading\">Parameters<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>$id<\/code><\/td><td><code>string<\/code><\/td><td>Unique identifier for the script module. Used in the import map.<\/td><\/tr><tr><td><code>$src<\/code><\/td><td><code>string<\/code><\/td><td>Full URL or path relative to WordPress root.<\/td><\/tr><tr><td><code>$deps<\/code><\/td><td><code>array<\/code><\/td><td>List of dependencies. See Dependencies section below.<\/td><\/tr><tr><td><code>$version<\/code><\/td><td><code>string|false|null<\/code><\/td><td>Version for cache busting. <code>false<\/code> = WP version, <code>null<\/code> = none.<\/td><\/tr><tr><td><code>$args<\/code><\/td><td><code>array<\/code><\/td><td>Additional arguments. See Args section below.<\/td><\/tr><\/tbody><\/table><\/figure><h3 class=\"wp-block-heading\">Dependencies Array<\/h3><p>Each dependency can be a string or an array:<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Simple string dependency (static import)\n$deps = array( &#039;@wordpress\/interactivity&#039; );\n\n\/\/ Array with import type\n$deps = array(\n    array(\n        &#039;id&#039;     =&gt; &#039;@wordpress\/interactivity&#039;,\n        &#039;import&#039; =&gt; &#039;static&#039;  \/\/ or &#039;dynamic&#039;\n    )\n);\n\n\/\/ Mixed\n$deps = array(\n    &#039;@wordpress\/interactivity&#039;,  \/\/ static\n    array( &#039;id&#039; =&gt; &#039;lazy-module&#039;, &#039;import&#039; =&gt; &#039;dynamic&#039; )\n);<\/code><\/pre><\/div><figure class=\"wp-block-table\"><table><thead><tr><th>Import Type<\/th><th>Behavior<\/th><\/tr><\/thead><tbody><tr><td><code>'static'<\/code><\/td><td>Preloaded via <code>&lt;link rel=&quot;modulepreload&quot;&gt;<\/code>, included in import map<\/td><\/tr><tr><td><code>'dynamic'<\/code><\/td><td>Only in import map, for runtime <code>import()<\/code> calls<\/td><\/tr><\/tbody><\/table><\/figure><h3 class=\"wp-block-heading\">Args Array<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Key<\/th><th>Type<\/th><th>Default<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>in_footer<\/code><\/td><td><code>bool<\/code><\/td><td><code>false<\/code><\/td><td>Print in footer (block themes only)<\/td><\/tr><tr><td><code>fetchpriority<\/code><\/td><td><code>string<\/code><\/td><td><code>'auto'<\/code><\/td><td><code>'auto'<\/code>, <code>'low'<\/code>, or <code>'high'<\/code><\/td><\/tr><\/tbody><\/table><\/figure><h3 class=\"wp-block-heading\">Example<\/h3><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Basic registration\nwp_register_script_module(\n    &#039;my-plugin\/gallery&#039;,\n    plugins_url( &#039;js\/gallery.js&#039;, __FILE__ ),\n    array( &#039;@wordpress\/interactivity&#039; ),\n    &#039;1.0.0&#039;\n);\n\n\/\/ With all options\nwp_register_script_module(\n    &#039;my-plugin\/heavy-feature&#039;,\n    plugins_url( &#039;js\/heavy-feature.js&#039;, __FILE__ ),\n    array(\n        &#039;@wordpress\/interactivity&#039;,\n        array( &#039;id&#039; =&gt; &#039;my-plugin\/utils&#039;, &#039;import&#039; =&gt; &#039;dynamic&#039; )\n    ),\n    &#039;2.0.0&#039;,\n    array(\n        &#039;in_footer&#039;     =&gt; true,\n        &#039;fetchpriority&#039; =&gt; &#039;low&#039;\n    )\n);<\/code><\/pre><\/div><hr class=\"wp-block-separator\"\/><h2 class=\"wp-block-heading\">wp_enqueue_script_module()<\/h2><p>Marks the script module to be enqueued in the page.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">function wp_enqueue_script_module(\n    string $id,\n    string $src = &#039;&#039;,\n    array $deps = array(),\n    $version = false,\n    array $args = array()\n)<\/code><\/pre><\/div><p><strong>Since:<\/strong> 6.5.0<br \/>\n<strong>Updated:<\/strong> 6.9.0 \u2014 Added the <code>$args<\/code> parameter.<\/p><h3 class=\"wp-block-heading\">Parameters<\/h3><p>Same as <code>wp_register_script_module()<\/code>.<\/p><h3 class=\"wp-block-heading\">Description<\/h3><p>If a <code>$src<\/code> is provided and the script module has not been registered yet, it will be registered automatically. This allows registration and enqueuing in a single call.<\/p><h3 class=\"wp-block-heading\">Example<\/h3><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Enqueue a previously registered module\nwp_enqueue_script_module( &#039;my-plugin\/gallery&#039; );\n\n\/\/ Register and enqueue in one call\nwp_enqueue_script_module(\n    &#039;my-plugin\/lightbox&#039;,\n    plugins_url( &#039;js\/lightbox.js&#039;, __FILE__ ),\n    array( &#039;@wordpress\/interactivity&#039; ),\n    &#039;1.0.0&#039;\n);<\/code><\/pre><\/div><hr class=\"wp-block-separator\"\/><h2 class=\"wp-block-heading\">wp_dequeue_script_module()<\/h2><p>Unmarks the script module so it is no longer enqueued in the page.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">function wp_dequeue_script_module( string $id )<\/code><\/pre><\/div><p><strong>Since:<\/strong> 6.5.0<\/p><h3 class=\"wp-block-heading\">Parameters<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>$id<\/code><\/td><td><code>string<\/code><\/td><td>The identifier of the script module.<\/td><\/tr><\/tbody><\/table><\/figure><h3 class=\"wp-block-heading\">Example<\/h3><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Remove a module from the queue\nwp_dequeue_script_module( &#039;some-plugin\/unwanted-module&#039; );<\/code><\/pre><\/div><hr class=\"wp-block-separator\"\/><h2 class=\"wp-block-heading\">wp_deregister_script_module()<\/h2><p>Deregisters the script module.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">function wp_deregister_script_module( string $id )<\/code><\/pre><\/div><p><strong>Since:<\/strong> 6.5.0<\/p><h3 class=\"wp-block-heading\">Parameters<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>$id<\/code><\/td><td><code>string<\/code><\/td><td>The identifier of the script module.<\/td><\/tr><\/tbody><\/table><\/figure><h3 class=\"wp-block-heading\">Description<\/h3><p>Removes the script module from the registry entirely. Also dequeues it if it was enqueued.<\/p><h3 class=\"wp-block-heading\">Example<\/h3><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Remove a module completely\nwp_deregister_script_module( &#039;some-plugin\/unwanted-module&#039; );<\/code><\/pre><\/div><hr class=\"wp-block-separator\"\/><h2 class=\"wp-block-heading\">wp_default_script_modules()<\/h2><p>Registers all the default WordPress Script Modules.<\/p><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">function wp_default_script_modules()<\/code><\/pre><\/div><p><strong>Since:<\/strong> 6.7.0<\/p><h3 class=\"wp-block-heading\">Description<\/h3><p>Called automatically during WordPress initialization. Registers all core script modules from <code>wp-includes\/js\/dist\/script-modules\/<\/code>.<\/p><h3 class=\"wp-block-heading\">Registered Modules<\/h3><figure class=\"wp-block-table\"><table><thead><tr><th>Module ID<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>@wordpress\/interactivity<\/code><\/td><td>Interactivity API runtime (or <code>\/debug<\/code> in SCRIPT_DEBUG)<\/td><\/tr><tr><td><code>@wordpress\/interactivity-router<\/code><\/td><td>Client-side navigation support<\/td><\/tr><tr><td><code>@wordpress\/block-library\/*<\/code><\/td><td>View scripts for core blocks<\/td><\/tr><tr><td><code>@wordpress\/a11y<\/code><\/td><td>Accessibility announcements<\/td><\/tr><\/tbody><\/table><\/figure><h3 class=\"wp-block-heading\">Default Settings<\/h3><p>Core modules are registered with:<\/p><ul class=\"wp-block-list\"><li><code>fetchpriority: 'low'<\/code> \u2014 Not critical for initial render<\/li><li><code>in_footer: true<\/code> \u2014 Printed in footer<\/li><\/ul><p>Block library modules also receive client-side navigation support via <code>WP_Interactivity::add_client_navigation_support_to_script_module()<\/code>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Global functions for registering and managing script modules. Source: wp-includes\/script-modules.php wp_script_modules() Retrieves the main WP_Script_Modules instance. function wp_script_modules(): WP_Script_Modules Since: 6.5.0 Description Provides access to the singleton WP_Script_Modules instance, creating&#8230;<\/p>\n","protected":false},"featured_media":0,"template":"","meta":{"footnotes":""},"tags":[],"project":[658],"project_type":[749],"class_list":["post-5816","documentation","type-documentation","status-publish","hentry","project-script-modules","project_type-wordpress-reference"],"project_info":{"id":589,"name":"WordPress Core","slug":"wordpress-core"},"project_type_info":{"id":749,"name":"WordPress Reference","slug":"wordpress-reference"},"_links":{"self":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5816","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation"}],"about":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/types\/documentation"}],"version-history":[{"count":3,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5816\/revisions"}],"predecessor-version":[{"id":10992,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5816\/revisions\/10992"}],"wp:attachment":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/media?parent=5816"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/tags?post=5816"},{"taxonomy":"project","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/project?post=5816"},{"taxonomy":"project_type","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/project_type?post=5816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}