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

Align Group blocks left or right

programmeradmin4浏览0评论

I'd like to right-align a Group block within a wide column. Is there a way I can get the Groups to show the same alignment options as an Image block does?

Group blocks by default only provide "Wide Width" and "Full Width". I'm able to do the corresponding CSS myself, I just need an interface for the end-user.

I'd like to right-align a Group block within a wide column. Is there a way I can get the Groups to show the same alignment options as an Image block does?

Group blocks by default only provide "Wide Width" and "Full Width". I'm able to do the corresponding CSS myself, I just need an interface for the end-user.

Share Improve this question asked Jan 2, 2020 at 8:04 altalt 1314 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

OK, I found a way to do this after browsing the source code. I do note that the code that helped me lives under deprecated.js so it's possible this won't continue to work.

Here's the JS code I have in my plugin directory

function addAlignmentToGroups(settings, name) {
    if (name !== "core/group") {
        return settings;
    }

    return lodash.assign({}, settings, {
        supports: lodash.assign( {}, settings.supports, {
            align: ['wide', 'full', 'left', 'center', 'right']
        })
    });
}

wp.hooks.addFilter(
    'blocks.registerBlockType',
    'myapp/alignments/group-block',
    addAlignmentToGroups
);

And the PHP code to load it:

<?php

 function my_enqueue() {
     wp_enqueue_script(
         'my-align-blocks',
         plugins_url('dist/align-blocks.js', __FILE__),
         ['wp-blocks']
     );
 }

 add_action('enqueue_block_editor_assets', 'my_enqueue');

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论