use_block_editor_for_post_type() WordPress Function

The use_block_editor_for_post_type() function allows you to enable or disable the block editor for a specific post type. This can be useful if you want to use the block editor for some post types but not others.

use_block_editor_for_post_type( string $post_type ) #

Returns whether a post type is compatible with the block editor.


Description

The block editor depends on the REST API, and if the post type is not shown in the REST API, then it won’t work with the block editor.


Top ↑

Parameters

$post_type

(string)(Required)The post type.


Top ↑

Return

(bool) Whether the post type can be edited with the block editor.


Top ↑

Source

File: wp-admin/includes/post.php

function use_block_editor_for_post_type( $post_type ) {
	if ( ! post_type_exists( $post_type ) ) {
		return false;
	}

	if ( ! post_type_supports( $post_type, 'editor' ) ) {
		return false;
	}

	$post_type_object = get_post_type_object( $post_type );
	if ( $post_type_object && ! $post_type_object->show_in_rest ) {
		return false;
	}

	/**
	 * Filters whether a post is able to be edited in the block editor.
	 *
	 * @since 5.0.0
	 *
	 * @param bool   $use_block_editor  Whether the post type can be edited or not. Default true.
	 * @param string $post_type         The post type being checked.
	 */
	return apply_filters( 'use_block_editor_for_post_type', true, $post_type );
}


Top ↑

Changelog

Changelog
VersionDescription
5.0.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.

Show More