Wrap Core Blocks in Container
WordPress filter to wrap core Gutenberg blocks in a container div
★ 0stars
0forks
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/ankitydv22/wp-wrap-core-blocks/archive/refs/heads/main.zipReadme
WP Wrap Core Blocks
A simple WordPress snippet/plugin that wraps all core Gutenberg blocks in a <div class="container">.
Usage
- Copy the code from
wrap-core-blocks.phpinto your theme'sfunctions.php, or - Install it as a plugin by placing the file in
/wp-content/plugins/and activating it.
Code
function wrap_core_blocks_in_container( $block_content, $block ) {
if ( is_admin() || wp_is_json_request() ) {
return $block_content;
}
// Wrap all WordPress core Gutenberg blocks.
if (
! empty( $block['blockName'] ) &&
strpos( $block['blockName'], 'core/' ) === 0
) {
return '<div class="container">' . $block_content . '</div>';
}
return $block_content;
}
add_filter( 'render_block', 'wrap_core_blocks_in_container', 10, 2 );