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

by Ankit Yadav · github.com/ankitydv22/wp-wrap-core-blocks

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.zip

Readme

WP Wrap Core Blocks

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 );

Read the full README on GitHub →