[ Web Proxy ]
URL:
Viewing: https://developer.wordpress.org/reference/functions/use_block_editor_for_post_type/ [Back]  [Original]

use_block_editor_for_post_type() Function | Developer.WordPress.org Skip to content
WordPress.org

use_block_editor_for_post_type( string $post_type ): bool

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.

Parameters

$post_typestringrequired
The post type.

Return

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

Source

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 );
}

Hooks

apply_filters( ‘use_block_editor_for_post_type’, bool $use_block_editor, string $post_type )

Filters whether a post is able to be edited in the block editor.

UsesDescription
post_type_supports()wp-includes/post.php

Checks a post type’s support for a given feature.

post_type_exists()wp-includes/post.php

Determines whether a post type is registered.

apply_filters()wp-includes/plugin.php

Calls the callback functions that have been added to a filter hook.

get_post_type_object()wp-includes/post.php

Retrieves a post type object by name.

Show 2 moreShow less
Used byDescription
use_block_editor_for_post()wp-includes/post.php

Returns whether the post can be edited in the block editor.

WP_Screen::get()wp-admin/includes/class-wp-screen.php

Fetches a screen object.

Changelog

VersionDescription
6.1.0Moved to wp-includes from wp-admin.
5.0.0Introduced.

User Contributed Notes

  1. Skip to note 3 content
    // Enable Gutenberg editor for specific post types
    function enable_gutenberg_editor_for_post_types( $current_status, $post_type ) {
        // Define an array of post types where Gutenberg should be enabled
        $enabled_post_types = array( 'post', 'page', 'custom_post_type' );
    
        // Check if the current post type is in the enabled post types array
        if ( in_array( $post_type, $enabled_post_types ) ) {
            return true; // Enable Gutenberg editor
        }
    
        return $current_status; // Keep current editor status
    }
    add_filter( 'use_block_editor_for_post_type', 'enable_gutenberg_editor_for_post_types', 10, 2 );
    Log in to add feedback
  2. Skip to note 4 content
    /**
     * Disable Gutenberg editor for post types.
     */
    add_filter( 'use_block_editor_for_post_type', '__return_false' );
    Log in to add feedback

You must log in before being able to contribute a note or feedback.


Web Proxy Viewer  |  New URL  |  Original Page