Last active
September 20, 2024 10:06
-
-
Save mslinnea/4d0084b76896b21360e149e383d9ac09 to your computer and use it in GitHub Desktop.
WordPress Gutenberg Performance - Disable Block Editor Preload Paths
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Gutenberg_Performance; | |
/** | |
* Removes the Synced Patterns (reusable blocks) from the preload paths. | |
* Performance improvement for sites with large number of these blocks. | |
* | |
* @param array $paths Paths. | |
* | |
* @return array | |
*/ | |
function block_editor_rest_api_preload_paths( $paths ) { | |
return array_values( | |
array_filter( | |
$paths, | |
function ( $v ) { | |
return ! is_string( $v ) || ! str_starts_with( $v, '/wp/v2/blocks?context=edit' ); | |
}, | |
) | |
); | |
} | |
add_filter( 'block_editor_rest_api_preload_paths', __NAMESPACE__ . '\block_editor_rest_api_preload_paths', 999, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See Enhancing WordPress Stability: Addressing Gutenberg Block Editor Preloading Issues for further context.