Skip to content

Instantly share code, notes, and snippets.

@bacoords
Created November 28, 2023 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bacoords/aa3343fcba09963429b9781515acab20 to your computer and use it in GitHub Desktop.
Save bacoords/aa3343fcba09963429b9781515acab20 to your computer and use it in GitHub Desktop.
<?php
/**
* Render columns block with extra class
*
* @param string $block_content The block content about to be rendered.
* @param array $block The full block, including name and attributes.
* @return string
*/
function render_columns_block_class( $block_content, $block ) {
$columns = count( $block['innerBlocks'] );
$block_content = str_replace( 'wp-block-columns', 'wp-block-columns wp-block-columns-has-' . $columns, $block_content );
return $block_content;
}
add_filter( 'render_block_core/columns', 'render_columns_block_class', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment