Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Created March 25, 2021 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikejolley/111f4b80a77a1897964388b08d419b31 to your computer and use it in GitHub Desktop.
Save mikejolley/111f4b80a77a1897964388b08d419b31 to your computer and use it in GitHub Desktop.
<?php
// Add below code to theme functions.php to create the bug/button-styling block.
// Ref: https://core.trac.wordpress.org/ticket/52555
add_action(
'init',
function() {
wp_register_script( 'bug-button-styling', '', array( 'wp-blocks', 'wp-element', 'wp-server-side-render' ), '1.0', true );
wp_enqueue_script( 'bug-button-styling' );
wp_add_inline_script(
'bug-button-styling',
"
( function( blocks, element, serverSideRender ) {
blocks.registerBlockType( 'bug/button-styling', {
title: 'Bug Button Styling',
category: 'common',
edit: function() {
return element.createElement( serverSideRender, { block: 'bug/button-styling' } );
}
} );
}(
window.wp.blocks,
window.wp.element,
window.wp.serverSideRender
) );
"
);
register_block_type(
'bug/button-styling',
array(
'editor-script' => 'bug-button-styling',
'render_callback' => function() {
return '<div class="wp-block-button"><a href="#never-visited" class="wp-block-button__link">Link styled as a button</a></div>';
},
)
);
}
);
@mikejolley
Copy link
Author

Screenshot 2021-03-25 at 14 41 14

Screenshot 2021-03-25 at 14 41 03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment