SHARE
TWEET

Untitled

a guest Mar 19th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /*
  4.   Wrap Gutenberg blocks in a custom wrapper
  5.   .block-is-wrapped is for general use      
  6.  */
  7. function gutenberg_block_wrapper( $block_content, $block ) {
  8.  
  9.   // No block name? Most likely doesn't exist
  10.   if ( NULL === $block['blockName']  ) {
  11.     return;
  12.   }
  13.  
  14.   // We might need to steal the classname from the
  15.   // element and apply it to the parent wrapper we're adding
  16.   $blockClass = sanitize_title( $block['blockName'] );
  17.   if ( isset( $block['attrs']['className'] ) ) {
  18.     $blockClass = sanitize_title( $block['blockName'] ) . ' wrapped-' . $block['attrs']['className'];
  19.   }
  20.  
  21.   // Wrap the element in a wrapper
  22.   return sprintf(
  23.     '<section class="block-is-wrapped block-%s">%s</section>',
  24.     $blockClass,
  25.     $block_content
  26.   );
  27. }
  28.  
  29. add_filter( 'render_block', 'gutenberg_block_wrapper', 10, 2 );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top