images - Extend core block attributes in post content

I need help with adding attribute 'caption' of coreimage block into saved post content.Currently saved attrib

I need help with adding attribute 'caption' of core/image block into saved post content.

Currently saved attributes look like follow:

<!-- wp:image {"id":36,"sizeSlug":"large"} -->

I aim to it looks like this:

<!-- wp:image {"id":36,"sizeSlug":"large","caption":"my caption"} -->

So I tried to use wp filter blocks.getSaveElement:

function test(element, blockType, attributes) {
    if (blockType.name !== 'core/image') {
        return element;
    }

    console.log(attributes.caption); // here is my attribute available

    return element;
}

wp.hooks.addFilter('blocks.getSaveElement', 'whatever', test);

Unfortunately I still can not figure out, how to save my attribute into post content. Any help please?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744884093a4599014.html

相关推荐

  • images - Extend core block attributes in post content

    I need help with adding attribute 'caption' of coreimage block into saved post content.Currently saved attrib

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信