我希望在 Gutenberg 的默认按钮块中使用 Bootstrap 框架的默认按钮样式。
我找到了一种解决方案,可以删除 WordPress 中的默认样式并添加自己的样式。这是链接:https://www.billerickson.net/block-styles-in-gutenberg/。
我正在使用 Bill Erickson 的代码来删除默认样式并添加新样式。在我的情况下,是来自 Bootstrap 的 .btn-primary 样式。
我找到了一种解决方案,可以删除 WordPress 中的默认样式并添加自己的样式。这是链接:https://www.billerickson.net/block-styles-in-gutenberg/。
我正在使用 Bill Erickson 的代码来删除默认样式并添加新样式。在我的情况下,是来自 Bootstrap 的 .btn-primary 样式。
wp.domReady( () => {
wp.blocks.unregisterBlockStyle( 'core/button', 'default' );
wp.blocks.unregisterBlockStyle( 'core/button', 'outline' );
wp.blocks.unregisterBlockStyle( 'core/button', 'squared' );
wp.blocks.registerBlockStyle( 'core/button', {
name: 'btn',
label: 'Default',
isDefault: true,
});
wp.blocks.registerBlockStyle( 'core/button', {
name: 'btn-primary',
label: 'Primary',
} );
} );
这里有两个问题:
- WordPress错误地添加了类
- 它只添加了一个类,但Bootstrap需要至少两个
在添加类之后,这是按钮的代码:
<div class="wp-block-button aligncenter is-style-btn-primary">
<a class="wp-block-button__link" href="#">Button</a>
</div>
正如您所看到的,WordPress将新类添加到按钮周围的div中。它还将is-style-
添加到类中。
为了使用Bootstrap样式的按钮块,我需要像这样的代码:
<div class="wp-block-button aligncenter is-style-btn-primary">
<a class="btn btn-primary" href="#">Button</a>
</div>
这个类必须在<a>
标签内,同时我需要第二个类.btn
。
有没有办法将这两个类添加到<a>
标签中?