Skip to content

Instantly share code, notes, and snippets.

@aliaghdam
Last active December 1, 2025 17:27
Show Gist options
  • Select an option

  • Save aliaghdam/0d329c59f00a9a73dce1bb3c04ae3e81 to your computer and use it in GitHub Desktop.

Select an option

Save aliaghdam/0d329c59f00a9a73dce1bb3c04ae3e81 to your computer and use it in GitHub Desktop.
Allow inline HTML tags rendering in the Post Excerpt block in WordPress block editor.

This code snippet customizes the render callback for the WordPress core/post-excerpt block using the register_block_type_args filter to enable HTML tags in the front end of block.

How It Works

This code replaces the default render callback for the core/post-excerpt block with a custom implementation that:

  1. It removes the excerptLength attribute of block by setting it to null. The core render function checks the excerptLength and if that was not set, then do not escapes the HTML tags.
  2. Uses the original render_block_core_post_excerpt() function with the modified attributes to keep compatible with future core updates.

Note: By doing it, the excerpt length functionality will continue to work.

Usage

  1. Add this code to your WordPress theme's functions.php file, or
  2. Include it in a custom plugin
  3. The filter will automatically apply when WordPress registers the core/post-excerpt block
<?php
add_filter(
'register_block_type_args',
'blockera_replace_excerpt_block_render_callback',
10,
2
);
/**
* Replace the render callback for core/post-excerpt block.
*
* @param array $args The block type arguments.
* @param string $block_type The block type name.
* @return array
*/
function blockera_replace_excerpt_block_render_callback($args, $block_type): array {
if ( 'core/post-excerpt' === $block_type ) {
$args['render_callback'] = 'blockera_render_block_core_post_excerpt';
}
return $args;
}
/**
* Custom render callback for post-excerpt block.
*
* @param array $attributes Block attributes.
* @param string $content Block content.
* @param WP_Block $block Block instance.
* @return string Rendered block output.
*/
function blockera_render_block_core_post_excerpt( $attributes, $content, $block ) {
$attributes['excerptLength'] = null;
return render_block_core_post_excerpt( $attributes, $content, $block );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment