filter_block_content() WordPress Function

The filter_block_content() function is a built-in WordPress function that allows you to filter the content of a block. This function is useful for making sure that your content is safe and clean before it is displayed on your website. You can use this function to remove unwanted HTML tags, characters, or images from your content.

filter_block_content( string $text, array[]|string $allowed_html = 'post', string[] $allowed_protocols = array() ) #

Filters and sanitizes block content to remove non-allowable HTML from parsed block attribute values.


Parameters

$text

(string)(Required)Text that may contain block content.

$allowed_html

(array[]|string)(Optional)An array of allowed HTML elements and attributes, or a context name such as 'post'.

Default value: 'post'

$allowed_protocols

(string[])(Optional)Array of allowed URL protocols.

Default value: array()


Top ↑

Return

(string) The filtered and sanitized content result.


Top ↑

Source

File: wp-includes/blocks.php

function filter_block_content( $text, $allowed_html = 'post', $allowed_protocols = array() ) {
	$result = '';

	$blocks = parse_blocks( $text );
	foreach ( $blocks as $block ) {
		$block   = filter_block_kses( $block, $allowed_html, $allowed_protocols );
		$result .= serialize_block( $block );
	}

	return $result;
}


Top ↑

Changelog

Changelog
VersionDescription
5.3.1Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.