render block – nested shortcodes

[ad_1]

I show in my documentation how to use the plugins shortcodes. I work with the default block editor and I get annoyed every time the block is rendered incorrectly, because I forgot to write it in [prismatic_code][/prismatic_code] tags. So I wrote a function that prevents this. Maybe you could include it in the plugin or put it in the FAQ.

add_filter(
  'render_block',
  function ( $block_content, $block ) {
    if ( $block['blockName'] === 'prismatic/blocks' ) {
      if (strpos($block['innerHTML'], 'prismatic_code') === false) {
        return str_replace("[","[",$block['innerHTML']);
      }
    }
    return $block_content;
  },
  10,
  2
);

Edit: The replaced character should be & # 0 9 1 ; without spaces.

  • This topic was modified 6 hours, 49 minutes ago by hupe13. Reason: The second [ in str_replace should be [
  • This topic was modified 6 hours, 47 minutes ago by hupe13.
  • This topic was modified 6 hours, 46 minutes ago by hupe13.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer