-
-
Save gcordner/bfe922da1a9bfe52d465d44fa169ccbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
This offered in response to this tweet by carrie dils: https://twitter.com/briancoords/status/1729589304593162558
For Christmas, I wish there was an auto-class applied to the Columns block indicating the number of child elements. Sure would be nicer than relying on content editors to add a custom CSS class.