Title: _remove_theme_attribute_in_block_template_content
Published: February 3, 2022
Last modified: May 20, 2026

---

# _remove_theme_attribute_in_block_template_content( string $template_content ): string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/_remove_theme_attribute_in_block_template_content/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/_remove_theme_attribute_in_block_template_content/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/_remove_theme_attribute_in_block_template_content/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/_remove_theme_attribute_in_block_template_content/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_remove_theme_attribute_in_block_template_content/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/_remove_theme_attribute_in_block_template_content/?output_format=md#wp--skip-link--target)

This function has been deprecated since 6.4.0. Use traverse_and_serialize_blocks(
parse_blocks( $template_content ), ‘_remove_theme_attribute_from_template_part_block’)
instead.

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Parses a block template and removes the theme attribute from each template part.

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

 `$template_content`stringrequired

Serialized block template content.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/_remove_theme_attribute_in_block_template_content/?output_format=md#return)󠁿

 string Updated block template content.

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

    ```php
    function _remove_theme_attribute_in_block_template_content( $template_content ) {
    	_deprecated_function(
    		__FUNCTION__,
    		'6.4.0',
    		'traverse_and_serialize_blocks( parse_blocks( $template_content ), "_remove_theme_attribute_from_template_part_block" )'
    	);

    	$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;
    }
    ```

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

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

| Uses | Description | 
| [_flatten_blocks()](https://developer.wordpress.org/reference/functions/_flatten_blocks/)`wp-includes/block-template-utils.php` |

Returns an array containing the references of the passed blocks and their inner blocks.

  | 
| [serialize_block()](https://developer.wordpress.org/reference/functions/serialize_block/)`wp-includes/blocks.php` |

Returns the content of a block, including comment delimiters, serializing all attributes from the given parsed block.

  | 
| [parse_blocks()](https://developer.wordpress.org/reference/functions/parse_blocks/)`wp-includes/blocks.php` |

Parses blocks out of a content string.

  | 
| [_deprecated_function()](https://developer.wordpress.org/reference/functions/_deprecated_function/)`wp-includes/functions.php` |

Marks a function as deprecated and inform when it has been used.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/_remove_theme_attribute_in_block_template_content/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_remove_theme_attribute_in_block_template_content/?output_format=md#)

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

| Version | Description | 
| [6.4.0](https://developer.wordpress.org/reference/since/6.4.0/) | Deprecated. Use traverse_and_serialize_blocks( parse_blocks( $template_content ), `'_remove_theme_attribute_from_template_part_block'` ) instead. | 
| [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. |

## User Contributed Notes

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