Hiding default editor (Gutenberg or not)

Support General Hiding default editor (Gutenberg or not)

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #38927
    ChrisChris
    Participant

    Is there a way to hide the default editor on page (not on a CPT) when I setup Custom fields through metabox?

    I would like to hide Gutenberg and the default non-block editor from these pages.

    #38946
    PeterPeter
    Moderator

    Hello Chris,

    You can use this PHP code to remove the editor if you want

    // Remove the editor. Change 'post' to your custom post type.
    add_action( 'init', function () {
        remove_post_type_support( 'post', 'editor' );
    } );

    Read more on the documentation https://docs.metabox.io/save-wysiwyg-content-post-content/

    #38955
    ChrisChris
    Participant

    Thanks,

    that woudl affect all pages, what if I only want to choose specifg pages by ID or such?

    #38961
    PeterPeter
    Moderator

    You can use this PHP code to get the post ID and create a condition to check it before removing the editor.

    $post_id = null;
    if ( isset( $_GET['post'] ) ) {
        $post_id = intval( $_GET['post'] );
    } elseif ( isset( $_POST['post_ID'] ) ) {
        $post_id = intval( $_POST['post_ID'] );
    }

    the correct code will look like

    // Remove the editor for a specific post. Change 'post' to your custom post type.
    add_action( 'init', function () {
        $post_id = null;
        if ( isset( $_GET['post'] ) ) {
            $post_id = intval( $_GET['post'] );
        } elseif ( isset( $_POST['post_ID'] ) ) {
            $post_id = intval( $_POST['post_ID'] );
        }
        if( $post_id == 1 ) {
            remove_post_type_support( 'post', 'editor' );    
        }
    } );
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.