php – Gutenberg Blocks and get_option() for styling


I’m creating a Gutenberg block and I’m trying to customize a button’s style (background color, text color, etc.) and it’s inner text with hexcode set in an options menu.

What’s the best way to access options in the database for wp.blocks.registerBlockType?

wp.blocks.registerBlockType('plugin/block', {
  title: 'Button',
  icon: 'analytics',
  category: 'common',
  edit: function () {
    return <h1>Button</h1>
  save: function () {
    return (
      <button style="background-color: {get_option('button-color')}">

Trying this just leads to a blank screen on the editor.

Soveric Eric 2 years 2021-11-26T03:44:41-05:00 0 Answers 0 views 0

Leave an answer