-
-
Save mikejolley/111f4b80a77a1897964388b08d419b31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>'; | |
}, | |
) | |
); | |
} | |
); |
Author
mikejolley
commented
Mar 25, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment