Removing the Editor from a WordPress Post Type
The WordPress editor has gotten a lot better over the years. However, You don't always want to use it. For example, a custom post type used for photo galleries doesn't need the editor; but how do you remove the editor from a WordPress post type?
By using the remove_post_type_support() function.
Custom Post Type
Following the idea of a gallery post type all it needs are photos. So it makes sense to remove the editor.
Here is how to do that with the registered post type name of gallery:
- Open your themes
functions.phpfile. - Pass the post type ID as the first argument for
remove_post_type_support(). - Then, call the function during the
initaction and set the priority to 99.
<?php // functions.php
add_action( 'init', function() {
remove_post_type_support( 'gallery', 'editor' );
}, 99);
Note: Setting the priority to 99 will make sure it is called after your post type has been registered. You can always increase the number. 99999 might work better for you.
Posts and Pages
If you want to remove the editor from the post and page post types do can do the same.
add_action( 'init', function() {
remove_post_type_support( 'post', 'editor' );
remove_post_type_support( 'page', 'editor' );
}, 99);
Support Title Only
If you are registering a post type with TypeRocket Pro and only want the main title field you can use the setSupports() method instead.
tr_post_type('Gallery')->setSupports(['title']);
WordPress Supports List
WordPress has a list of features any post type can add or remove support for.
-
titlefor the main title field. -
editorfor the WordPress editor. -
authorfor the publishing author select box. -
thumbnailfor the featured image. -
excerptfor the excerpt meta box. -
trackbacksfor trackbacks if the content is linked to externally. -
custom-fieldsfor the WordPress built-in custom fields meta box. -
commentsfor comments. -
revisionsfor revisions of the post type. -
page-attributesfor template and menu order (hierarchical only). -
post-formatsfor post formats.