As of April 2023, if you're looking to disable or remove the Image block from the Gutenberg editor in WordPress entirely, or prevent its JavaScript module (image-js-module or similar) from loading, WordPress doesn't provide a direct filter specifically for disabling a single block's JavaScript file. However, WordPress does allow you to unregister blocks, which can effectively disable them within the editor.
To unregister a block in WordPress, you can use the wp.blocks.unregisterBlockType JavaScript function. This is typically done within an admin script that you enqueue specifically for the block editor.
Below is an example of how to unregister the Image block:
(function(wp) {
wp.domReady(function() {
wp.blocks.unregisterBlockType('core/image');
});
}(window.wp));
Here's how you can enqueue this script correctly to affect the block editor:
-
Create a JavaScript file (for this example, let's call it disable-image-block.js) in your theme or plugin directory and place the above JavaScript code inside it.
-
Enqueue this script in your theme's functions.php file or within your plugin, making sure to target the block editor specifically. Here's how you can do that:
function mytheme_disable_image_block() {
wp_enqueue_script(
'disable-image-block', // Handle
get_template_directory_uri() . '/path/to/disable-image-block.js', // Path to the file
array( 'wp-blocks', 'wp-dom-ready', 'wp-edit-post' ), // Dependencies
filemtime(get_template_directory() . '/path/to/disable-image-block.js') // Version, for caching; this uses the file modification time.
);
}
add_action('enqueue_block_editor_assets', 'mytheme_disable_image_block');
This will effectively remove the Image block from the Gutenberg editor's available blocks. Keep in mind this does not affect any image blocks that have already been added to posts or pages; it merely prevents the block from being added in the future.
If your goal is different from removing or disabling the Image block (e.g., disabling a specific feature or script within the Image block without removing it), you may need a different approach, possibly involving custom JavaScript to modify the block's behavior.
Important considerations: Make sure to replace /path/to/disable-image-block.js with the actual path to your JavaScript file within your theme or plugin structure. Additionally, approach modifications to the editor with caution to ensure you do not inadvertently disrupt the content creation process on your site.