Title: render_block
Published: December 6, 2018
Last modified: August 20, 2026

---

# apply_filters( ‘render_block’, string $block_content, array $block, WP_Block $instance )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/render_block/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/render_block/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/render_block/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/render_block/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/render_block/?output_format=md#user-contributed-notes)

Filters the content of a single block.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/render_block/?output_format=md#parameters)󠁿

 `$block_content`string

The block content.

`$block`array

The full block, including name and attributes.

`$instance`[WP_Block](https://developer.wordpress.org/reference/classes/wp_block/)

The block instance.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/render_block/?output_format=md#source)󠁿

    ```php
    $block_content = apply_filters( 'render_block', $block_content, $this->parsed_block, $this );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/class-wp-block.php#L717)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/class-wp-block.php#L717-L717)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/render_block/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_Block::render()](https://developer.wordpress.org/reference/classes/wp_block/render/)`wp-includes/class-wp-block.php` |

Generates the render output for the block.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/render_block/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | The `$instance` parameter was added. | 
| [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/render_block/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 5 content](https://developer.wordpress.org/reference/hooks/render_block/?output_format=md#comment-content-3072)
 2.    [Khoi Pro](https://profiles.wordpress.org/khoipro/)  [  8 years ago  ](https://developer.wordpress.org/reference/hooks/render_block/#comment-3072)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frender_block%2F%23comment-3072)
     Vote results for this note: 5[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frender_block%2F%23comment-3072)
 4.  To add a div wrapper outside of some blocks (like `core/paragraph` or `core/heading`),
     you can add filter to `render_block`:
 5.      ```php
         // functions.php
         function wporg_block_wrapper( $block_content, $block ) {
         	if ( $block['blockName'] === 'core/paragraph' ) {
         		$content = '<div class="wp-block-paragraph">';
         		$content .= $block_content;
         		$content .= '</div>';
         		return $content;
         	} elseif ( $block['blockName'] === 'core/heading' ) {
         		$content = '<div class="wp-block-heading">';
         		$content .= $block_content;
         		$content .= '</div>';
         		return $content;
         	}
         	return $block_content;
         }
     
         add_filter( 'render_block', 'wporg_block_wrapper', 10, 2 );
         ```
     
 6.   * This doesn’t work anymore I’m afraid as all core blocks have their `blockName`
        set to null for some obscure reason :( [https://github.com/WordPress/WordPress/blob/master/wp-includes/blocks.php#L697](https://github.com/WordPress/WordPress/blob/master/wp-includes/blocks.php#L697)
      * [petrey](https://profiles.wordpress.org/smpetrey/) [5 years ago](https://developer.wordpress.org/reference/hooks/render_block/#comment-5140)
 7.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frender_block%2F%3Freplytocom%3D3072%23feedback-editor-3072)
 8.   [Skip to note 6 content](https://developer.wordpress.org/reference/hooks/render_block/?output_format=md#comment-content-5701)
 9.    [Marie Comet](https://profiles.wordpress.org/chaton666/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/render_block/#comment-5701)
 10. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frender_block%2F%23comment-5701)
     Vote results for this note: 4[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frender_block%2F%23comment-5701)
 11. `$block
      (array) The full block, including name and attributes.
 12. Good to know that `$block['attrs']` do not include attributes declared in block.
     json with “source” set to “attribute”.
 13. For example, in a block.json :
 14.     ```javascript
         "attributes": {
             "url": {
                 "type": "string",
                 "source": "attribute",
                 "selector": "a",
                 "attribute": "href"
             },
             "width": {
                 "type": "number"
             }
         }
         ```
     
 15. `$block['attrs']` only include `width`, not `url`.
 16.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frender_block%2F%3Freplytocom%3D5701%23feedback-editor-5701)
 17.  [Skip to note 7 content](https://developer.wordpress.org/reference/hooks/render_block/?output_format=md#comment-content-5865)
 18.   [Phil Johnston](https://profiles.wordpress.org/johnstonphilip/)  [  4 years ago  ](https://developer.wordpress.org/reference/hooks/render_block/#comment-5865)
 19. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frender_block%2F%23comment-5865)
     Vote results for this note: 4[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frender_block%2F%23comment-5865)
 20. Here’s a quick/rough example of how you can render any block in any way with this
     filter. Note that the example uses an attribute called `name_of_attribute_here`.
     You’ll want to use an actual attribute that belongs to that block.
 21. A quick/easy way to discover what’s available to you is to `print_r( $block );`
     inside the function, refresh the frontend page where the block sits, and see what’s
     available in the `attrs`.
 22.     ```php
         /**
          * Modify the rendered output of any block.
          *
          * @param string $block_content The normal block HTML that would be sent to the screen.
          * @param array  $block An array of data about the block, and the way the user configured it.
          */
         function my_custom_render( $block_content, $block ) {
     
         	// For the block in question, render whatever you want, and pull any attrinute you need from $block['attrs'].
         	if ( $block['blockName'] === 'core/image' ) {
         		return 'Anything I want with any attribute value here: ' . $block['attrs']['name_of_attribute_here'] . '.';
         	}
     
         	// For any other block, just return normal block output.
         	return $block_content;
     
         }
         add_filter( 'render_block', 'my_custom_render', 10, 2 );
         ```
     
 23.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frender_block%2F%3Freplytocom%3D5865%23feedback-editor-5865)
 24.  [Skip to note 8 content](https://developer.wordpress.org/reference/hooks/render_block/?output_format=md#comment-content-6606)
 25.   [Benjamin Intal](https://profiles.wordpress.org/bfintal/)  [  3 years ago  ](https://developer.wordpress.org/reference/hooks/render_block/#comment-6606)
 26. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frender_block%2F%23comment-6606)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frender_block%2F%23comment-6606)
 27. `$block_content` and `$block` can become `null`, so be sure to handle these cases.
 28.     ```php
         function wpdocs_render_block( $block_content, $block ) {
         	if ( is_null( $block_content ) ) {
         		// Handle null
         	}
     
         	if ( isset( $block['blockName'] ) && 'wpdocs/block' === $block['blockName'] ) {
         		// Do something
         	}
     
         	return $block_content;
         }
         add_filter( 'render_block', 'wpdocs_render_block', 10, 2 );
         ```
     
 29.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frender_block%2F%3Freplytocom%3D6606%23feedback-editor-6606)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frender_block%2F)
before being able to contribute a note or feedback.