Skip to content

Instantly share code, notes, and snippets.

@khleomix
Last active February 16, 2022 20:35
Show Gist options
  • Save khleomix/1e02b1de0481d727a86381016359fd83 to your computer and use it in GitHub Desktop.
Save khleomix/1e02b1de0481d727a86381016359fd83 to your computer and use it in GitHub Desktop.
Block Variations
<?php
wp.blocks.registerBlockVariation(
'core/columns',
{
name: 'unicorn',
title: 'Unicorn',
isDefault: true, // will override core block and remove it from the inserter, set to false or remove to use as a separate block.
attributes: {
className: 'unicorn-columns',
},
icon: 'buddicons-activity',
scope: [ 'inserter' ],
innerBlocks: [
[ 'core/column', {},
[
[ 'core/heading',
{
level: 3,
content: 'Column 1 Heading',
}
],
[ 'core/paragraph',
{
content: 'Lorem ipsum dolor sit amet id erat aliquet diam ullamcorper tempus massa eleifend vivamus.'
}
],
]
],
[ 'core/column', {},
[
[ 'core/heading',
{
level: 3,
content: 'Column 2 Heading',
}
],
[ 'core/paragraph',
{
content: 'Morbi augue cursus quam pulvinar eget volutpat suspendisse dictumst mattis id.'
}
],
]
],
],
}
);
wp.blocks.registerBlockVariation(
'core/cover',
{
name: 'dogs',
title: 'Dogs',
isDefault: true,
attributes: {
className: 'dog-hero',
align: 'full',
contentAlign: 'left',
backgroundType: 'image',
url: 'https://jcnextjs.local/wp-content/uploads/2021/04/hero.jpg',
},
icon: 'carrot',
innerBlocks: [
[ 'core/heading',
{
level: 1,
content: 'They’re good dogs, Brent',
}
],
[ 'core/paragraph',
{
content: 'The only Legit Source for Professional Dog Ratings on the web.'
}
],
[ 'core/button',
{
text: 'Get your rating',
backgroundColor: 'vivid-cyan-blue',
textColor: 'white',
url: '#',
},
],
[ 'core/button',
{
text: 'Dispute a rating',
className: 'is-style-outline',
textColor: 'white',
url: '#',
},
],
],
}
);
wp.blocks.registerBlockVariation(
'core/heading',
{
name: 'green-text',
title: 'Green Text',
description: 'This block has green text.',
attributes: {
content: 'Green Text',
level: 1,
textColor: 'vivid-green-cyan'
},
icon: 'palmtree',
scope: [ 'inserter' ]
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment