【发布时间】:2020-04-04 13:56:59
【问题描述】:
我已经制作了一个自定义的古腾堡块:
(function(blocks, components, element) {
var el = element.createElement;
var registerBlockType = blocks.registerBlockType;
var TextControl = components.TextControl;
registerBlockType("blocks/test-block", {
title: "Test Block",
description: "A custom block.",
icon: "businessman",
category: "common",
attributes: {
headline: {
type: "string"
}
},
edit: function(props) {
var headline = props.attributes.headline;
var onHeadlineChange = function(val) {
props.setAttributes({
headline: val
});
};
return el(TextControl, {
value: headline,
label: "Headline",
onChange: onHeadlineChange
});
},
save: function(props) {
alert('');
return el(
"h3",
{
className: "headline"
},
props.attributes.headline
);
}
});
})(window.wp.blocks, window.wp.components, window.wp.element);
我想在前端加载块时运行一个函数。
我尝试了save 函数,但它仅在块保存在 wp-dashboard 时才有效。
有什么方法可以在加载块时运行函数吗?
【问题讨论】:
标签: wordpress block wordpress-gutenberg gutenberg-blocks create-guten-block