> For the complete documentation index, see [llms.txt](https://benjaminzekavica.gitbook.io/gutenberg/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://benjaminzekavica.gitbook.io/gutenberg/plugins/custom-styles.md).

# Custom Styles

### Methode als Funktion

Damit ich mich im Code nicht direkt wiederholen musst, schreibe ich lieber eine Funktion und gebe ihr Parameter mit.&#x20;

| Name & Hinweise                                                             | Type   |
| --------------------------------------------------------------------------- | ------ |
| $blockname \| Gebe den Namespace von deinem Block an                        | String |
| $classname  \| Gebe hier die CSS Klasse, die dann mit is-style concat. wird | String |
| $label            \| Dieses Label wird im Backend angezeigt                 | String |

```jsx
// Globale Funktion wird geschrieben
function StyleGutenbergRegister( $blockname , $classname, $labelname) {
    wp.blocks.registerBlockStyle( $blockname, {
        name:  $classname,  
        label: $labelname
    });
}

// Funktion wird aufgerufen und Parameter werden mitgegeben
StyleGutenbergRegister( 'prwp-blocks/featureblock', 'dotted', 'Gepunktet'); 
```

### Methode direkt im RegisterBlockType&#x20;

Falls du dies nicht als Funktion extern haben möchtest, kannst du innerhalb vom der RegisterBlockType Funktion  zum Beispiel unter den Attributen diesen Code Block einfügen.&#x20;

```jsx
styles: [
	{
		name: "prwp__bg--default",
		label: __("Hintergrund Weiß"),
		isDefault: true
	},
	{
		name: "prwp__bg--grey",
		label: __("Hintergrund Grau")
	},
	{
		name: "prwp__bg--yellow",
		label: __("Hintergrund Gelb")
	}
],
```

#### Erläuterungen&#x20;

```jsx
isDefault: true
```

Mittels diesem Befehlen kannst du einen Standard definieren und dieser wird automatisch ausgewählt. Pro Objekt Branch kannst einen CSS/HTML Klasse definieren und einen Label angeben, welcher dann im Backend angezeigt wird.&#x20;

### Style deaktivieren

Falls du einen Style entfernen möchtest, kannst du dies so tun:&#x20;

```jsx
// Erster Parameter: Namespace des Blocks mit dem Style  
// Zweiter Parameter: Style Name 

wp.blocks.unregisterBlockStyle( 'core/quote', 'large' );

// Falls React dies nicht erkennt, verwende die DomReady Funktion
wp.domReady( function() {
    wp.blocks.unregisterBlockStyle( 'core/quote', 'large' );
} );
```

Weitere besonderen Filter Methoden findest du übrigens hier: \
[**Gutenberg Handbook**](https://developer.wordpress.org/block-editor/developers/filters/block-filters/)&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://benjaminzekavica.gitbook.io/gutenberg/plugins/custom-styles.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
