Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
_remove_theme_attribute_in_block_template_content() WordPress Function
The remove_theme_attribute_in_block_template_content() function allows you to remove an attribute from a given block template content. This is useful if you want to remove an attribute from a template that is used by multiple blocks.
_remove_theme_attribute_in_block_template_content( string $template_content ) #
Parses a block template and removes the theme attribute from each template part.
Parameters
- $template_content
(string)(Required)Serialized block template content.
Return
(string) Updated block template content.
Source
File: wp-includes/block-template-utils.php
function _remove_theme_attribute_in_block_template_content( $template_content ) { $has_updated_content = false; $new_content = ''; $template_blocks = parse_blocks( $template_content ); $blocks = _flatten_blocks( $template_blocks ); foreach ( $blocks as $key => $block ) { if ( 'core/template-part' === $block['blockName'] && isset( $block['attrs']['theme'] ) ) { unset( $blocks[ $key ]['attrs']['theme'] ); $has_updated_content = true; } } if ( ! $has_updated_content ) { return $template_content; } foreach ( $template_blocks as $block ) { $new_content .= serialize_block( $block ); } return $new_content; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.9.0 | Introduced. |