Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
Register same custom styles to multiple block types in gutenberg

I want to add some styles to more than one block type.

At the moment I'm doing this for every block type like this and change only the part 'core/paragraph' to 'core/heading' for example.

Is there any way to do this for more than one block at the same time?

wp.blocks.registerBlockStyle(
'core/paragraph',
[
    {
        name: 'default',
        label: 'Default',
        isDefault: true,
    },
    {
        name: 'lead',
        label: 'Lead',
    },
    {
        name: 'subline',
        label: 'Subline',
    },
]
);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you know names of the blocks you want to add your styles to, you can use registerBlockStyle() in a forEach() loop to mass register multiple styles to multiple blocks, eg:

const blocks = ["core/quote", "core/heading", "core/paragraph"]; //etc..

const styles = [
    {
        name: 'default',
        label: 'Default',
        isDefault: true,
    },
    {
        name: 'lead',
        label: 'Lead',
    },
    {
        name: 'subline',
        label: 'Subline',
    }
];

// Loop through each block and register all custom styles in one go..
blocks.forEach(function(blocks) {
    wp.blocks.registerBlockStyle(blocks, [...styles]);
});

To find the names of all currently registered blocks, use:

wp.blocks.getBlockTypes().map(block => block.name);

Even though you could apply your styles to every block, please use it sparingly only on required blocks - not every block all at once..

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda