I need to create an extra style for WP Gutenberg Gallery block with a custom look and feel for front-end.

I'm trying to create custom style using wp.blocks.registerBlockStyle(). But for my goal, I need to use a custom save function.

Can I do it? Or maybe exist any another way to solve the problem?

  • Are you saying you're trying to set this style inline? If it's just pure CSS you could include it in your theme or a plugin, inspecting the elements to figure out how to target specific elements. Each block has a specific class that identifies what kind of block it is, so you can only affect the gallery block using that class. – WebElaine Jan 31 '19 at 17:12
  • @WebElaine The method wp.blocks.registerBlockStyle() provide me the choice for style choosing meanwhile I add gallery block, it is very useful for me. But also I need to change the output layout and add extra classes to items. – trolik Jan 31 '19 at 20:23
  • Ok, for changing more than just CSS - actually changing HTML such as adding classes - you'll want to look into Block Filters. Try the Gutenberg Handbook and see if that helps: wordpress.org/gutenberg/handbook/designers-developers/… – WebElaine Jan 31 '19 at 21:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.