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.

_block_template_render_without_post_block_context() WordPress Function

The block_template_render_without_post_block_context() function is used to render a block template without the post block context. This is useful for blocks that need to be rendered outside of the post context, such as in the sidebar or in a custom template.

_block_template_render_without_post_block_context( array $context ) #

Removes post details from block context when rendering a block template.


Parameters

$context

(array)(Required)Default context.


Top ↑

Return

(array) Filtered context.


Top ↑

Source

File: wp-includes/block-template.php

function _block_template_render_without_post_block_context( $context ) {
	/*
	 * When loading a template directly and not through a page that resolves it,
	 * the top-level post ID and type context get set to that of the template.
	 * Templates are just the structure of a site, and they should not be available
	 * as post context because blocks like Post Content would recurse infinitely.
	 */
	if ( isset( $context['postType'] ) && 'wp_template' === $context['postType'] ) {
		unset( $context['postId'] );
		unset( $context['postType'] );
	}

	return $context;
}

Top ↑

Changelog

Changelog
VersionDescription
5.8.0Introduced.

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.