WP Manifestindependent plugin directory
manifest / editor / wp-wrap-core-blocks

Wrap Core Blocks in Container

WordPress filter to wrap core Gutenberg blocks in a container div

★ 0stars

Install

Download source zip No release zip yet

This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.

Install straight from GitHub with WP-CLI:

wp plugin install https://github.com/ankitydv22/wp-wrap-core-blocks/archive/refs/heads/main.zip
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

A simple WordPress snippet/plugin that wraps all core Gutenberg blocks in a <div class="container">.

Usage

  1. Copy the code from wrap-core-blocks.php into your theme's functions.php, or
  2. 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 );