Title: core blocks
Last modified: February 11, 2022

---

# core blocks

 *  [kmytort](https://wordpress.org/support/users/kmytort/)
 * (@kmytort)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/core-blocks/)
 * Hello, I have been trying to apply an apply_filter like this for hours
 * `echo apply_filters( 'render_block', $blockContent, $block )`;
 * ////////////////////////////////////////////////// / //////////////////
 *     ```
       add_filter('render_block', 'display_post_heading', 10, 2);
       show_post_header() function {
       global post $;
       $blocks = parse_blocks ($post->post_content);
       foreach ($blocks as $block) {
       if( 'core/heading' === $block['blockName'] ) {
       echo render_block($block);
       break;
       }
       }
       ```
   
 * can someone guide me on the path of the light of worpress

Viewing 11 replies - 1 through 11 (of 11 total)

 *  Moderator [t-p](https://wordpress.org/support/users/t-p/)
 * (@t-p)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/core-blocks/#post-15356434)
 * I recommend asking at [https://github.com/WordPress/gutenberg/issues](https://github.com/WordPress/gutenberg/issues)
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/core-blocks/#post-15356545)
 * It’s not clear to me what you want to accomplish. You would normally use `apply_filters()`
   where you want to allow others to modify something your code is doing without
   having to directly modify your code. `render_block()` already calls `apply_filters()`
   for “render_block”, so why would you also do so?
 * If you want to modify how all blocks are rendered, you can add to the “render_block”
   filter to do so. It doesn’t make sense to `apply_filters()` for that. If you 
   only wish to target a specific block, the “render_block_{$this->name}” filter
   would make more sense.
    [https://developer.wordpress.org/reference/hooks/render_block_this-name/](https://developer.wordpress.org/reference/hooks/render_block_this-name/)
 *  Thread Starter [kmytort](https://wordpress.org/support/users/kmytort/)
 * (@kmytort)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/core-blocks/#post-15356952)
 * and the {$this->name}” what is the name? the name of the osae filter would be
   like this? My problem is that I don’t understand how to put the apply_filter()
 * `echo apply_filters( "render_block_{$this->display_post_heading}", $blockContent,
   $block );`
    can you guide me please, because nothing works for me
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/core-blocks/#post-15358714)
 * I could advise better if I understood what you wish to accomplish. Without such
   understanding, I suspect `apply_filters()` is unlikely to accomplish what you
   want. I’ve been modifying what WP does for many years and have never used it.
   OTOH, `add_filter()` is very frequently used.
 * More on filter use is described in the [Plugin Handbook](https://developer.wordpress.org/plugins/hooks/filters/).
 * To use `"render_block_{$this->name}"`, replace `{$this->name}` with the block
   object’s name property where you wish to filter its rendered content. Thus you
   only filter a specific block instead of all blocks.
 *  Thread Starter [kmytort](https://wordpress.org/support/users/kmytort/)
 * (@kmytort)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/core-blocks/#post-15363418)
 * Hello, thanks for answering, what I want is to take the paragraph or the columns
   or any block of the core in `the_contet().` and so separate them or take these
   blocks in another html tag, I don’t want to customize them I just want to take
   the paragraph and put it somewhere else and`<h1> <?php echo the_title()?></h1
   >,` and that’s how I call the paragraph but I don’t know how to do it `apply_filters('
   render_block', $blockContent, $block );`
    you can help?
 *  Thread Starter [kmytort](https://wordpress.org/support/users/kmytort/)
 * (@kmytort)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/core-blocks/#post-15363425)
 * ///page.php ///
    <div> <?php //echo ‘
    - ‘ . $blockContent . ‘
    - ‘;
       apply_filters( ‘render_block’, $blockContent, $block ); ?> <?php //echo
      display_post_paragraph();?> </div>
    - ///functions.php ///
    -     ```
          function post_paragraph() {
           global $post;
          	$blocks = parse_blocks( $post->post_content );
          	foreach( $blocks as $block ) {
          		if( 'core/paragraph' === $block['blockName'] ) {
                echo render_block( $block);
                break;
              }
            }
          }
          ```
      
 *  Thread Starter [kmytort](https://wordpress.org/support/users/kmytort/)
 * (@kmytort)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/core-blocks/#post-15363736)
 * it’s supposed to work like this `apply_filters( "render_block_{$this->post_paragraph}",
   $blockContent, $block );`
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/core-blocks/#post-15363748)
 * If you want to move blocks about in content, “render_block” will not help because
   it only operates on one block at a time and has no knowledge of surrounding context.
 * You could use “the_content” filter to do so though. In your filter callback use`
   preg_replace()` to find and extract the targeted blocks, or `explode()` the entire
   content into smaller elements. Insert extracted blocks elsewhere or rearrange
   as desired. Return the modified content.
 * Add your callback to “the_content” filter with `add_filter()`. No need to use`
   apply_filter()` at all. Do use a larger $priority arg value to give other callbacks
   a chance to modify content before your code has a go at it. WP will call `apply_filters()`
   at the appropriate time, which will cause your added callback to execute.
 *  Thread Starter [kmytort](https://wordpress.org/support/users/kmytort/)
 * (@kmytort)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/core-blocks/#post-15369278)
 * Hello, thank you very much for your help, I managed to make this variable, but
   I only printed the text, my question is if I do it with a gallery?
 *     ```
       $ content = get_the_content () ; 
                       if (preg_match ('~ <p class = "info-text-block"> ([\ s \ S] +?) </p> ~ ', $ content, $ matches)) 
                   echo '<P>' . $ matches [1] . '</p>' ;
       ```
   
    -  This reply was modified 4 years, 3 months ago by [bcworkz](https://wordpress.org/support/users/bcworkz/).
      Reason: code format fixed
 *  Thread Starter [kmytort](https://wordpress.org/support/users/kmytort/)
 * (@kmytort)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/core-blocks/#post-15372103)
 * Hello, again me, now I have the same problem but with the media-text block .
 * As I can, call only the middle block – text ?
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/core-blocks/#post-15372188)
 * Getting the regexp right can be tricky. Try one of regexp “fiddle” sites like
   regexr.com. Paste in your content as a sample, then experiment with the regexp
   until it captures what you want and not what you don’t want.

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘core blocks’ is closed to new replies.

## Tags

 * [block](https://wordpress.org/support/topic-tag/block/)
 * [media](https://wordpress.org/support/topic-tag/media/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [the_content](https://wordpress.org/support/topic-tag/the_content/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 11 replies
 * 3 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [4 years, 3 months ago](https://wordpress.org/support/topic/core-blocks/#post-15372188)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
