Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Created Mar 25, 2021
Embed
What would you like to do?
<?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

This comment has been minimized.

Copy link
Owner Author

@mikejolley mikejolley commented Mar 25, 2021

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