Random WordPress Function

Learn about a new WordPress function every day!


Function Signature:

wp_should_load_block_editor_scripts_and_styles

Function Description:

Checks if the editor scripts and styles for all registered block types should be enqueued on the current screen.

Function Examples:

⚠️ Examples below are generated with GPT-3 once every hour. Do not take them too seriously.
Consider them as some extra input in your learning process - reason about them. Will it work? What could fail?
// Example 1: Checking if block editor scripts and styles should be loaded
$should_load = wp_should_load_block_editor_scripts_and_styles();

if ( $should_load ) {
    // Enqueue block editor scripts and styles
    wp_enqueue_script( 'wp-blocks' );
    wp_enqueue_style( 'wp-block-editor' );
} else {
    // Load custom scripts and styles instead
    wp_enqueue_script( 'custom-scripts' );
    wp_enqueue_style( 'custom-styles' );
}
// Example 2: Using a specific post ID to determine if block editor scripts and styles should be loaded
$post_id = get_the_ID();
$should_load = wp_should_load_block_editor_scripts_and_styles( $post_id );

if ( $should_load ) {
    // Enqueue block editor scripts and styles
    wp_enqueue_script( 'wp-blocks' );
    wp_enqueue_style( 'wp-block-editor' );
} else {
    // Load custom scripts and styles instead
    wp_enqueue_script( 'custom-scripts' );
    wp_enqueue_style( 'custom-styles' );
}
// Example 3: Checking if block editor scripts and styles should be loaded for a specific post type
$post_type = 'post';
$should_load = wp_should_load_block_editor_scripts_and_styles( null, $post_type );

if ( $should_load ) {
    // Enqueue block editor scripts and styles
    wp_enqueue_script( 'wp-blocks' );
    wp_enqueue_style( 'wp-block-editor' );
} else {
    // Load custom scripts and styles instead
    wp_enqueue_script( 'custom-scripts' );
    wp_enqueue_style( 'custom-styles' );
}