Custom WP Blocks (register_block_type) in a Parent Theme

It sounds like the issue might be related to the way WordPress loads parent and child themes, and how it handles functions that are defined in both.

When a child theme is active, WordPress loads the functions.php file from the child theme first, and then loads the parent theme’s functions.php file. If there is a function with the same name in both files, the function in the child theme will override the function in the parent theme.

In your case, it’s possible that the child theme’s functions.php file is defining a function with the same name as the create_block_custom_block_init function that is defined in the parent theme. When this happens, the child theme’s version of the function will be used instead of the parent theme’s version, which may cause the blocks to disappear.

To avoid this issue, you can try prefixing the function name in the parent theme with a unique string, such as the parent theme’s name or a custom prefix. For example:

function parent_theme_prefix_create_block_custom_block_init() {
    register_block_type(DIR . '/build');
}
add_action('init', 'parent_theme_prefix_create_block_custom_block_init');

By prefixing the function name with a unique string, you can ensure that the function in the parent theme is not overridden by a function in the child theme with the same name.

If this doesn’t solve the issue, you can also try using the wp_enqueue_script() function to load the block’s JavaScript file in the parent theme’s functions.php file. This can help ensure that the block’s scripts are loaded correctly even when a child theme is active.