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.
This code replaces the default render callback for the core/post-excerpt block with a custom implementation that:
- It removes the
excerptLengthattribute of block by setting it tonull. The core render function checks theexcerptLengthand if that was not set, then do not escapes the HTML tags. - 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.
- Add this code to your WordPress theme's
functions.phpfile, or - Include it in a custom plugin
- The filter will automatically apply when WordPress registers the
core/post-excerptblock