最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to make a block similar to another block

programmeradmin1浏览0评论

My immediate goal is to add a block type that's the same as an existing block type, except for the name. Then I can use CSS to style it appropriately. This would be used (via the block editor) by non-technical folks, so telling them to add a block of the initial type, then go to Advanced -> Additional CSS Class is not a good idea. I've tried several ways to reach my goal, but come to a roadblock for each, so the question is: is there a simple way, or do I need to create a custom block type from scratch?

(Below attempts are hypothetically in PHP in a plugin, or in some simple JavaScript code.)

First, I thought there would something simple in the API that would directly do what I want. But I didn't see anything.

Then I thought I'd do it myself by getting some block type object, copying and modifying it, then giving that to registerBlockType. But I couldn't find a function to get info about a block type.

Finally, I thought I'd create a block template out of some container block enclosing the block I wanted to base things off of. Again, CSS could easily be used to make the template look as I desired. But there don't seem to be any suitable container blocks.

The various approaches could be questions in their own right. As often is the case, it's hard to be sure of the best question granularity.

发布评论

评论列表(0)

  1. 暂无评论