Support » Developing with WordPress » Custom Block + Custom Post Types = wp.blockEditor is undefined

  • Hello,

    I made a few Custom Blocks and they work fine in posts and pages.

    In custom post types I get the message the console that wp.blockEditor is undefined, and I can’t use the blocks.

    I think I am forgetting something when I declare my CPT, but can’t find what. I’ve also search the whole morning on the net and can’t find any reference to that issue :/

    Here’s how I register the CPT and the Block:

    function q_product_cpt() {
        if( function_exists('register_post_type') ) :
            $lables_cpt_product = array(
                'name'                  => _x( 'Products', 'Post Sector General Name', 'q_product' ),
                'singular_name'         => _x( 'Product', 'Post Sector Singular Name', 'q_product' ),
                'menu_name'             => _x( 'Products', 'Admin Menu text', 'q_product' ),
                'name_admin_bar'        => _x( 'Product', 'Add New on Toolbar', 'q_product' ),
                'add_new'               => __( 'Add New', 'q_product' ),
            $args_cpt_product = array(
                'label'                => __( 'Products', 'q_product' ),
                'description'          => __( 'Products', 'q_product' ),
                'labels'               => $lables_cpt_product,
                'supports'            => array( 'title', 'custom-fields', 'editor', 'author', 'revisions', 'page-attributes' ),
                'hierarchical'         => false,
                'public'               => true,
                'can_export'           => true,
                'has_archive'          => true,
                'exclude_from_search'  => false,
                'capability_type'      => 'post',
                'show_in_rest'         => true,
            register_post_type( 'product', $args_cpt_product);
    add_action( 'init', 'q_product_cpt', 0 );

    Here’s how I register the Block:

    add_action( 'init', function() {
        wp_register_script('quasi-header-js', plugin_dir_url( __FILE__ ) . 'template-parts/blocks/quasi-header.js');
        register_block_type('quasi/header', [
            'editor_script' => 'quasi-header-js',
    }, 10);

    And the actual error message in the console:
    Uncaught TypeError: can't access property "RichText", wp.blockEditor is undefined. I have this message even when I create an empty block and try to desctructure the RichText component

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Maybe you are looking for wp.blocks.editor

    Thread Starter quasiDigi


    Thanks for your suggestion but when I try wp.blocks.editor the error is also in pages and posts. With wp.blockEditor, the error is only there for the custom post type.
    For this reason I think the problem might be in how I registered the custom post type.

    Thread Starter quasiDigi


    I’ve re-installed my dev environment. This time with create-guten-block and it works smoothly. Exactly the same code! đŸ˜€

    So, I probably did some mistake in my setup. I’m still wondering why the blocks were working on pages and posts but not on custom posts….

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.