我无法为wordpress站点注册gutenberg块,当我看到控制台时它显示错误
'Uncaught TypeError: wp.blocks.blockRegisterType不是custom-cta-script.js的函数?版本= 1:1:11 '
有人能帮忙修理一下吗?
js文件的队列代码:
function include_cta_js()
{
wp_enqueue_script('custom-cta-script', plugin_dir_url(__FILE__) . 'custom-cta-script.js', array(
'wp-blocks', 'wp-editor'
), true, false);
}
add_action('enqueue_block_editor_assets', 'include_cta_js');
JS文件:
wp.blocks.blockRegisterType('custom-cta-script/custom-block', {
title: 'CTA',
icon: 'smiley',
category: 'text',
attributes: {
text: { type: 'string' },
url: { type: 'string' },
backgroundColor: { type: 'string' },
textColor: { type: 'string' }
},
edit: function (props) {
return React.createElement("div", null, /*#__PURE__*/React.createElement("label", null, "Button Text"), /*#__PURE__*/React.createElement("input", {
type: "text",
value: "",
placeholder: "Button Text"
}), /*#__PURE__*/React.createElement("label", null, "Button URL"), /*#__PURE__*/React.createElement("input", {
type: "text",
value: "",
placeholder: "Button URL"
}), /*#__PURE__*/React.createElement("label", null, "Button Background Color"), /*#__PURE__*/React.createElement("input", {
type: "text",
value: "",
placeholder: "Button Background Color"
}), /*#__PURE__*/React.createElement("label", null, "Button Text Color"), /*#__PURE__*/React.createElement("input", {
type: "text",
value: "",
placeholder: "Button Text Color"
}));
},
save: function (props) {
return null;
}
});
从Gutenberg版本5.8开始,wp.blocks.registerBlockType()
函数取代wp.blocks.blockRegisterType()
函数注册自定义块。因此,您应该将JavaScript代码中的wp.blocks.blockRegisterType
替换为wp.blocks.registerBlockType
。