Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WP Gutenberg, remove core panel options?

Does anyone know if it's posssible to remove some of the default panels from the core blocks in gutenberg?

I'm thinking specifically of, the color palette panel (only on some blocks, like I don't want the user to be able to change colors on the buttons). or Button border radius... same with core/cover height.

I've tried almost everything I can think of, and wondering if I have to create my own custom blocks just for these small changes.

like image 585
Cinta Avatar asked Dec 07 '25 11:12

Cinta


1 Answers

I tried experimenting with altering the block settings.supports object with some luck... I say some because I wasn't able to completely remove all the panels I wanted but did manage to remove things like color and typography panels like this.

Reference link(s)

  • WP Block Ref.
import assign from "lodash.assign";
import { addFilter } from "@wordpress/hooks";

const extendOnBlocks = ["core/button"]; // replace with ["core/cover"]

const removeBlockPanels = (settings, name) => {
  // Do nothing if it's another block than our defined ones.
  if (!extendOnBlocks.includes(name)) {
    return settings;
  }

  // Use Lodash's assign to gracefully handle if attributes are undefined
  settings.supports = assign(settings.supports, {
    __experimentalBorder: false,
    typography: false,
    color: false,
  });

  return settings;
};
addFilter(
  "blocks.registerBlockType",
  "my-button/attribute/options",
  removeBlockPanels
);
like image 97
Omar Avatar answered Dec 09 '25 20:12

Omar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!